少年修仙传客户端代码仓库
xingchen Qiu
2019-04-10 b45f84d1a84cb768d0b136fe37ad18364d74af1f
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, April 10, 2018
//--------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text.RegularExpressions;
using System.Text;
using Snxxz.UI;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class AnimationFadeOut : MonoBehaviour
    {
        [Header("每列个数")]
        public int LINE = 4;
        [SerializeField] Transform m_OblNull;
        [SerializeField] LineFadeOut m_LineFadeOut1;
        [SerializeField] LineFadeOut m_LineFadeOut2;
        [SerializeField] LineFadeOut m_LineFadeOut3;
        [SerializeField] Animator m_Animator;
 
        [SerializeField] CanvasGroup m_CanvasGroup;
 
        Dictionary<int, List<Transform>> AnimationFadeOutDic = new Dictionary<int, List<Transform>>();
        Dictionary<int, Transform> tranDic = new Dictionary<int, Transform>();
 
        public void Init()
        {
            
            PositionReduction();
            Classify();
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChange;
        }
        public void Unit()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChange;
        }
 
        public void FadeOut()//淡出
        {
            m_Animator.Play("MainFadeIn");
        }
        public void FadeIn()//淡入
        {
            m_Animator.Play("MainFadeOut");
        }
 
        public void ImmediatelyAppear()//立刻出现
        {
            m_Animator.Play("ImmediatelyAppear", 0, 1);
        }
 
        public void FadeAtOnce()//立刻消失
        {
            m_Animator.Play("FadeAtOnce", 0, 1);
        }
 
        public bool GetIsFadeIn()//是否淡入
        {
            if (m_CanvasGroup.alpha < 0.5)
            {
                return false;
            }
            else
            {
                return true;
            }            
        }
 
        private void OnFuncStateChange(int obj)
        {
            PositionReduction();
            Classify();
        }
     
        private void Classify()
        {
            SetGroup();
            SetfatherNode();
 
        }
 
        private void SetGroup()//进行分组
        {
            AnimationFadeOutDic.Clear();
            tranDic.Clear();
            int Index = 0;
            for (int i = 0; i < m_OblNull.childCount; i++)
            {
                if (m_OblNull.GetChild(i).GetComponent<UIFuncOpen>() != null && !FuncOpen.Instance.IsFuncOpen(m_OblNull.GetChild(i).GetComponent<UIFuncOpen>().id))
                {
 
                }
                else
                {
                    if (m_OblNull.GetChild(i).GetComponent<PositionIndex>() != null)
                    {
                        if (!tranDic.ContainsKey(m_OblNull.GetChild(i).GetComponent<PositionIndex>().Index))
                        {
                            int index = m_OblNull.GetChild(i).GetComponent<PositionIndex>().Index;
                            tranDic.Add(index, m_OblNull.GetChild(i));
                        }
 
                    }
                    Index += 1;
                    int line = Mathf.CeilToInt((float)Index / LINE);
                    if (!AnimationFadeOutDic.ContainsKey(line))
                    {
                        List<Transform> tran = new List<Transform>();
                        tran.Add(m_OblNull.GetChild(i).transform);
                        AnimationFadeOutDic.Add(line, tran);
                    }
                    else
                    {
                        AnimationFadeOutDic[line].Add(m_OblNull.GetChild(i).transform);
                    }
                }
            }
 
        }
 
        private void SetfatherNode()//设置父节点
        {
            if (AnimationFadeOutDic.Count != 0)
            {
                foreach (var key in AnimationFadeOutDic.Keys)
                {
                    SwithSome(key, AnimationFadeOutDic[key]);                    
                }
            }
            else
            {
                m_LineFadeOut1.gameObject.SetActive(false);
                m_LineFadeOut2.gameObject.SetActive(false);
                m_LineFadeOut3.gameObject.SetActive(false);
            }
        }
 
 
        private void SwithSome(int key, List<Transform> list)
        {
            switch (key)
            {
                case 1:
                    m_LineFadeOut1.gameObject.SetActive(true);
                    for (int i = 0; i < list.Count; i++)
                    {
                        int index = i;
                        Node(m_LineFadeOut1, index, list[index]);
                    }
                    break;
                case 2:
                    m_LineFadeOut2.gameObject.SetActive(true);
                    for (int i = 0; i < list.Count; i++)
                    {
                        int index = i;
                        Node(m_LineFadeOut2, index, list[index]);
                    }
                    break;
                case 3:
                    m_LineFadeOut3.gameObject.SetActive(true);
                    for (int i = 0; i < list.Count; i++)
                    {
                        int index = i;
                        Node(m_LineFadeOut3, index, list[index]);
                    }
                    break;
            }
        }//进行分列
        private void Node(LineFadeOut lineFadeOut, int index, Transform tran)//设置进空盒子中
        {
            switch (index)
            {
                case 0:
                    tran.SetParent(lineFadeOut.OneParent);
                    tran.localPosition = Vector3.zero;
                    break;
                case 1:
 
                    tran.SetParent(lineFadeOut.TwoParent);
                    tran.localPosition = Vector3.zero;
                    break;
                case 2:
                    tran.SetParent(lineFadeOut.ThreeParent);
                    tran.localPosition = Vector3.zero;
                    break;
                case 3:
                    tran.SetParent(lineFadeOut.FourParent);
                    tran.localPosition = Vector3.zero;
                    break;
                default:
                    break;
            }
        }
 
        private void PositionReduction()//还原位置(把盒子中的位置全部重新拉出来)
        {
            if (tranDic.Count <= 0)
            {
                return;
            }
            foreach (var key in tranDic.Keys)
            {
                tranDic[key].SetParent(m_OblNull);
                tranDic[key].SetSiblingIndex(key);
            }
        }
 
     
    }
 
 
 
}