少年修仙传客户端代码仓库
client_Hale
2019-04-11 9f89e3be35da42eb9ccb44e6589d62f320aa444c
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Snxxz.UI;
 
public class CreateRoleBehaviour : MonoBehaviour
{
    [SerializeField] int m_Job;
    [SerializeField] float m_Scale = 1;
    [SerializeField] EnterPictureType m_EnterPictureType;
 
    [SerializeField] ShowAnimation m_EnterShowAnimation;
    [SerializeField] ShowAnimation m_RoutimeShowAnimation;
 
    [SerializeField] Effect[] m_PersistentEffect;
    [SerializeField] Effect[] m_EnterShowEffect;
    [SerializeField] Effect[] m_RoutimeShowEffect;
 
    [SerializeField] CreateRoleHeroPlatform m_Platform;
    [SerializeField] ActorShadowCaster m_Shadow;
 
    CreateRoleTimeLine showTimeLine = new CreateRoleTimeLine();
 
    public State state { get; private set; }
 
    List<SFXController> sfxControllers = new List<SFXController>();
 
    public void DoEnterShow()
    {
        CreateRoleManager.Instance.LoadModel(m_Job, (bool ok, UnityEngine.Object @object) =>
       {
           if (ok)
           {
               var model = @object as GameObject;
               model.transform.SetParentEx(m_Platform.transform, Vector3.zero, Quaternion.identity, Vector3.one * m_Scale);
               m_Shadow.Cast(model.transform);
               model.SetActive(true);
 
               ReleaseEffects();
 
               state = State.EnterShow;
               showTimeLine.ClearNode();
 
               foreach (var effect in m_PersistentEffect)
               {
                   showTimeLine.AddNone(effect.delay, () =>
                   {
                       PlayEffect(model.transform, effect);
                   });
               }
 
               foreach (var effect in m_EnterShowEffect)
               {
                   showTimeLine.AddNone(effect.delay, () =>
                   {
                       PlayEffect(model.transform, effect);
                   });
               }
 
               showTimeLine.AddNone(m_EnterShowAnimation.delay, () =>
               {
                   var animator = model.GetComponent<Animator>();
                   animator.Play(m_EnterShowAnimation.animation);
               });
 
               showTimeLine.AddNone(5f, () =>
               {
                   WindowCenter.Instance.Open<CreateRoleWin>();
               });
 
               showTimeLine.OnComplete(() => { state = State.Idle; });
               showTimeLine.Begin();
           }
       });
    }
 
    public void DoRoutineShow()
    {
        CreateRoleManager.Instance.LoadModel(m_Job, (bool ok, UnityEngine.Object @object) =>
        {
            if (ok)
            {
                var model = @object as GameObject;
                model.transform.SetParentEx(m_Platform.transform, Vector3.zero, Quaternion.identity, Vector3.one * m_Scale);
 
                switch (m_EnterPictureType)
                {
                    case EnterPictureType.OutIn:
                        model.SetActive(false);
                        break;
                    case EnterPictureType.Stand:
                        model.SetActive(true);
                        m_Shadow.Cast(model.transform);
                        break;
                }
 
                ReleaseEffects();
                state = State.RoutimeShow;
 
                showTimeLine.ClearNode();
                showTimeLine.AddNone(m_RoutimeShowAnimation.delay, () =>
                {
                    if (m_EnterPictureType == EnterPictureType.OutIn)
                    {
                        model.SetActive(true);
                        m_Shadow.Cast(model.transform);
                    }
 
                    var animator = model.GetComponent<Animator>();
                    animator.Play(m_RoutimeShowAnimation.animation);
                });
 
                foreach (var effect in m_PersistentEffect)
                {
                    showTimeLine.AddNone(effect.delay, () =>
                    {
                        PlayEffect(model.transform, effect);
                    });
                }
 
                foreach (var effect in m_RoutimeShowEffect)
                {
                    showTimeLine.AddNone(effect.delay, () =>
                    {
                        PlayEffect(model.transform, effect);
                    });
                }
 
                showTimeLine.AddNone(2f, () =>
                {
                    WindowCenter.Instance.Open<CreateRoleWin>();
                });
 
                showTimeLine.OnComplete(() => { state = State.Idle; });
                showTimeLine.Begin();
            }
        });
    }
 
    public void Dispose()
    {
        showTimeLine.Dispose();
        ReleaseEffects();
    }
 
    private void PlayEffect(Transform model, Effect effect)
    {
        var config = EffectConfig.Get(effect.id);
        Transform parent = null;
        if (!string.IsNullOrEmpty(config.nodeName))
        {
            parent = model.transform.GetChildTransformDeeply(config.nodeName);
        }
        else
        {
            parent = model.transform;
        }
 
        sfxControllers.Add(SFXPlayUtility.Instance.Play(effect.id, parent));
    }
 
    public void ReleaseEffects()
    {
        for (var i = sfxControllers.Count - 1; i >= 0; i--)
        {
            SFXPlayUtility.Instance.Release(sfxControllers[i]);
        }
 
        sfxControllers.Clear();
    }
 
    [System.Serializable]
    public struct ShowAnimation
    {
        public string animation;
        public float delay;
    }
 
    [System.Serializable]
    public struct Effect
    {
        public int id;
        public float delay;
    }
 
    public enum EnterPictureType
    {
        Stand,
        OutIn,
    }
 
    public enum State
    {
        Idle,
        EnterShow,
        RoutimeShow,
    }
 
}