少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 f1f2599ba0e6b64358ffef7ae5c9f9af3ed8b8b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    [DisallowMultipleComponent]
    public class CalculateLayout : MonoBehaviour
    {
        [Header("起始位置")]
        [SerializeField] public Vector3 starPos;
     
        [Header("预制体大小")]
        [SerializeField] Vector2 m_CellSize = new Vector2(100, 100);
        public Vector2 cellSize
        {
            get { return m_CellSize; }
        }
        [Header("间隔")]
        [SerializeField] public float m_SpacingY;
 
        [Header("延迟时间")]
        [SerializeField] public float delayTime = 0.1f;
 
        List<GameObject> golist;
 
        public void Init(List<GameObject> golist, bool _stepByStep = false)
        {
            this.golist = null;
            if (golist == null) return;
            this.gameObject.SetActive(true);
            this.golist = golist;
            if (_stepByStep)
            {
                for (int i = 0; i < golist.Count; i++)
                {
                    golist[i].SetActive(false);
                }
            }
 
            for(int i = 0; i < golist.Count;i++)
            {
                GameObject go = golist[i];
                float posX = starPos.x;
                float posY = starPos.y -(cellSize.y + m_SpacingY)*i;
                go.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(posX,posY,0);
            }
 
            if(_stepByStep)
            {
                StartCoroutine("Co_StepByStepAppear");
            }
        }
 
        IEnumerator Co_StepByStepAppear()
        {
            if(golist != null)
            {
                for (int i = 0; i < golist.Count; i++)
                {
                    golist[i].SetActive(true);
                    yield return new WaitForSeconds(delayTime);
                }
            }
        }
 
        private void OnDisable()
        {
            golist = null;
        }
    }
 
}