少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, October 26, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class StatusTipWin : Window
    {
 
        private List<TipController> m_TipList = new List<TipController>();
        private Stack<TipController> m_FreeList = new Stack<TipController>();
        private List<TipController> m_RemoveList = new List<TipController>();
 
        public int displayCount;
        public float moveDuration;
        public int space;
 
        public bool useLanguage;
        public string tip = "您获得了<color=red>[{0}]</color>的状态";
        public TipController original;
 
        private bool m_StartMove;
        private Vector2 m_DistanceOffset;
        private float m_MoveSpeed;
        private float m_MoveDistance;
        private float m_MoveTime;
        private float m_TopLimit;
 
        bool inited = false;
 
        [SerializeField] RectTransform m_ContainerSpecialBuff;
        [SerializeField] PositionTween m_SpeicalBuffTween;
        [SerializeField] UIAlphaTween m_SpecialBuffAlplaTween;
        [SerializeField] int m_SpecialBuffId;
        #region Built-in
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            StatusMgr.OnGainStatus += OnGainStatus;
            for (int i = 0; i < m_TipList.Count; ++i)
            {
                m_TipList[i].Recyle();
                m_FreeList.Push(m_TipList[i]);
            }
            m_TipList.Clear();
            m_ContainerSpecialBuff.gameObject.SetActive(false);
        }
 
        protected override void LateUpdate()
        {
            base.LateUpdate();
 
            //if (Input.GetKeyDown(KeyCode.Space))
            //{
            //    OnGainStatus("测试测试");
            //}
 
            if (m_MoveTime > 0)
            {
                for (int i = 0; i < m_TipList.Count; ++i)
                {
                    m_TipList[i].rectTransform.anchoredPosition += Vector2.up * m_MoveSpeed * Time.deltaTime;
 
                    if (m_TipList[i].rectTransform.anchoredPosition.y > m_TopLimit)
                    {
                        if (!m_RemoveList.Contains(m_TipList[i]))
                        {
                            m_RemoveList.Add(m_TipList[i]);
 
                            //Debug.LogFormat("checkY: {0}, originalY: {1}, topY: {2}",
                            //    m_TipList[i].rectTransform.anchoredPosition.y,
                            //    original.rectTransform.anchoredPosition.y,
                            //    m_TopLimit);
                        }
                    }
 
                    if (m_TipList[i].rectTransform.anchoredPosition.y > original.rectTransform.anchoredPosition.y)
                    {
                        m_TipList[i].Play();
                    }
 
                }
 
                m_MoveTime -= Time.deltaTime;
 
                if (m_MoveTime < 0)
                {
                    m_MoveTime = 0;
                }
            }
 
            for (int i = 0; i < m_TipList.Count; ++i)
            {
                if (m_TipList[i].isFadeOut)
                {
                    if (!m_RemoveList.Contains(m_TipList[i]))
                    {
                        m_RemoveList.Add(m_TipList[i]);
                    }
                }
 
            }
 
            for (int i = 0; i < m_RemoveList.Count; ++i)
            {
                m_RemoveList[i].Recyle();
                m_TipList.Remove(m_RemoveList[i]);
                m_FreeList.Push(m_RemoveList[i]);
            }
 
            m_RemoveList.Clear();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            StatusMgr.OnGainStatus -= OnGainStatus;
            for (int i = 0; i < m_TipList.Count; ++i)
            {
                m_TipList[i].Recyle();
            }
            m_TipList.Clear();
 
            while (m_FreeList.Count > 0)
            {
                var behaviour = m_FreeList.Pop();
                behaviour.Recyle();
            }
        }
 
        protected override void OnAfterClose()
        {
        }
 
        protected override void OnActived()
        {
            base.OnActived();
 
            if (!inited)
            {
                m_MoveDistance = original.rectTransform.sizeDelta.y + space;
                m_MoveSpeed = m_MoveDistance / moveDuration;
                m_TopLimit = original.rectTransform.anchoredPosition.y;
                m_TopLimit += (original.rectTransform.sizeDelta.y + space) * displayCount;
                original.gameObject.SetActive(false);
                inited = true;
            }
        }
 
        #endregion
 
        private void OnGainStatus(int skillId)
        {
            var skillConfig = SkillConfig.Get(skillId);
            if (skillConfig != null)
            {
                if (skillConfig.SkillTypeID == m_SpecialBuffId)
                {
                    DisplaySpecialTip();
                }
                else
                {
                    DisplayLabelTip(skillConfig.SkillName);
                }
            }
        }
 
        void DisplayLabelTip(string buffName)
        {
            TipController _newController = null;
            if (m_FreeList.Count > 0)
            {
                _newController = m_FreeList.Pop();
            }
            else
            {
                GameObject _new = Instantiate(original.gameObject);
                _newController = _new.GetComponent<TipController>();
            }
            string _content = string.Format(tip, buffName);
            _newController.Init(_content);
            _newController.transform.SetParent(transform);
            if (m_TipList.Count == 0)
            {
                _newController.transform.localPosition = original.transform.localPosition;
            }
            else
            {
                _newController.transform.localPosition = m_TipList[m_TipList.Count - 1].transform.localPosition - new Vector3(0, m_MoveDistance, 0);
            }
            _newController.transform.localScale = original.transform.localScale;
 
            m_TipList.Add(_newController);
 
            m_MoveTime += moveDuration;
        }
 
        void DisplaySpecialTip()
        {
            transform.SetAsLastSibling();
            m_SpeicalBuffTween.SetStartState();
            m_SpecialBuffAlplaTween.SetStartState();
            m_SpeicalBuffTween.enabled = false;
            m_SpecialBuffAlplaTween.enabled = false;
            m_ContainerSpecialBuff.gameObject.SetActive(true);
            m_SpeicalBuffTween.enabled = true;
            m_SpeicalBuffTween.Play(OnSpecialBuffComplete);
        }
 
        private void OnSpecialBuffComplete()
        {
            m_SpecialBuffAlplaTween.enabled = true;
            m_SpecialBuffAlplaTween.Play(OnSpecialBuffAlphaComplete);
        }
 
        private void OnSpecialBuffAlphaComplete()
        {
            m_ContainerSpecialBuff.gameObject.SetActive(false);
        }
    }
 
 
}