少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, October 10, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
 
 
 
namespace vnxbqy.UI
{
 
    public class FunctionUnlockFlyObject : MonoBehaviour
    {
        public static event Action<bool, int> functionUnLockShowBeginEvent;
        public static event Action<FunctionUnlockType> functionUnLockShowEndEvent;
 
        [SerializeField] Image m_FunctionIcon;
        [SerializeField] RawImage m_TreasureIcon;
        [SerializeField] UIEffect m_Effect;
 
        int m_Id = 0;
        FunctionUnlockType m_UnLockType;
        FunctionUnlockFlyObjectTarget target;
 
        Vector3 originalPosition = Vector3.zero;
        float originalScale = 2f;
        float speed = 6f;
        float durationLimit = 10f;
        float timer = 0f;
 
        bool beginMove = false;
 
        Action onReached;
 
        public void SetContent(FunctionUnlockType _type, int _id)
        {
            SetSpeed(10f);
 
            m_UnLockType = _type;
            m_Id = _id;
 
            switch (_type)
            {
                case FunctionUnlockType.Treasure:
                    UI3DTreasureExhibition.Instance.ShowTreasure(m_Id, m_TreasureIcon);
                    originalScale = 9f;
                    break;
                case FunctionUnlockType.Normal:
                    var config = FuncOpenLVConfig.Get(m_Id);
                    m_FunctionIcon.SetSprite(config.Icon);
                    originalScale = 2f;
                    break;
                case FunctionUnlockType.TreasureSkill:
                    Treasure _treaure;
                    ModelCenter.Instance.GetModel<TreasureModel>().TryGetTreasure(m_Id, out _treaure);
                    var _skillCfg = SkillConfig.Get(_treaure.skillId);
                    m_FunctionIcon.SetSprite(_skillCfg.IconName);
                    m_FunctionIcon.SetNativeSize();
                    originalScale = 1f;
                    break;
                case FunctionUnlockType.Skill:
                    var skillConfig = SkillConfig.Get(m_Id);
                    m_FunctionIcon.SetSprite(skillConfig.IconName);
                    originalScale = 1f;
                    break;
                case FunctionUnlockType.TreasureFunc:
                    UI3DTreasureExhibition.Instance.ShowTreasure(m_Id, m_TreasureIcon);
                    originalScale = 9f;
                    break;
                case FunctionUnlockType.TreasureChapter:
                    originalScale = 1.5f;
                    var treasureConfig = TreasureConfig.Get(m_Id);
                    m_FunctionIcon.SetSprite(treasureConfig.Icon);
                    break;
            }
 
            this.transform.localScale = Vector3.one * originalScale;
            if (m_Effect != null)
            {
                m_Effect.Play();
            }
 
            target = FunctionUnlockFlyObjectTargetCenter.GetTarget(m_UnLockType, m_Id);
            if (target != null)
            {
                target.Prepare();
                beginMove = false;
            }
        }
 
        public void SetContent(int _id, int _skillId)
        {
            m_UnLockType = FunctionUnlockType.Treasure;
            m_Id = _id;
 
            var skillConfig = SkillConfig.Get(_skillId);
            m_FunctionIcon.SetSprite(skillConfig.IconName);
            originalScale = 1f;
            this.transform.localScale = Vector3.one * originalScale;
            if (m_Effect != null)
            {
                m_Effect.Play();
            }
 
            target = FunctionUnlockFlyObjectTargetCenter.GetTarget(m_UnLockType, m_Id);
            if (target != null)
            {
                target.Prepare();
                beginMove = false;
            }
        }
 
        public void SetSpeed(float _speed)
        {
            speed = _speed;
        }
 
        public void SetScale(float _scale)
        {
            originalScale = _scale;
        }
 
        public void Begin(Action _callBack)
        {
            onReached = _callBack;
 
            if (target == null)
            {
                if (onReached != null)
                {
                    onReached();
                    onReached = null;
                }
 
                StopTreasureShow();
 
                GameObject.Destroy(this.gameObject);
                return;
            }
 
            if (functionUnLockShowBeginEvent != null)
            {
                functionUnLockShowBeginEvent(target.mainWinUnFold, target.skillGroup);
            }
 
            timer = 0f;
            this.SetActive(true);
            SoundPlayer.Instance.PlayUIAudio(22);
            StartCoroutine(Co_WaitOneFrameToStart());
        }
 
        IEnumerator Co_WaitOneFrameToStart()
        {
            yield return null;
            originalPosition = this.transform.position.SetZ(0);
            beginMove = true;
        }
 
        private void LateUpdate()
        {
            if (!beginMove)
            {
                return;
            }
 
            timer += Time.deltaTime;
 
            var to = target.transform.position.SetZ(0);
            var normalizeDir = Vector3.Normalize(to - this.transform.position.SetZ(0));
            var delta1 = normalizeDir * speed * Time.deltaTime;
            var delta2 = to - this.transform.position.SetZ(0);
            var delta = Vector3.Magnitude(delta1) < Vector3.Magnitude(delta2) ? delta1 : delta2;
            this.transform.Translate(delta);
 
            var scaleT = 1 - Vector3.Distance(to, this.transform.position) / Vector3.Distance(originalPosition, to);
            this.transform.localScale = Vector3.one * Mathf.Lerp(originalScale, 1, scaleT);
 
            if (timer > durationLimit || Vector3.Distance(to, this.transform.position.SetZ(0)) < 0.1f || !WindowCenter.Instance.IsOpen<MainInterfaceWin>())
            {
                try
                {
                    if (onReached != null)
                    {
                        onReached();
                        onReached = null;
                    }
 
                    target.ResponseFunctionUnLock();
                    if (m_Effect != null)
                    {
                        m_Effect.Stop();
                    }
 
                    if (functionUnLockShowEndEvent != null)
                    {
                        functionUnLockShowEndEvent(m_UnLockType);
                    }
 
                    StopTreasureShow();
 
                    GameObject.Destroy(this.gameObject);
                }
                catch (Exception ex)
                {
                    DebugEx.Log(ex.Message);
                }
            }
 
        }
 
        void StopTreasureShow()
        {
            switch (m_UnLockType)
            {
                case FunctionUnlockType.Treasure:
                case FunctionUnlockType.TreasureSkill:
                case FunctionUnlockType.TreasureFunc:
                    UI3DTreasureExhibition.Instance.Stop();
                    break;
            }
        }
    }
 
}