少年修仙传客户端代码仓库
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
using vnxbqy.UI;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
 
public class ShowActor
{
    public GameObject m_Model { get; private set; }
    private int m_NpcId = 0;
    public int npcId { get { return m_NpcId; } }
 
    private int m_Index = 0;
    private int m_Instance = 0;
    private NPCConfig m_NpcCfg = null;
    public ActorShowConfig actorShowModel = null;
    private Animator m_Animator;
    private RuntimeAnimatorController m_CacheAnimator;
    private int m_CacheLayer;
    private int m_CacheEffectLayer;
    private Vector3 m_CacheScale;
 
    SFXController sfxController;
 
    private SFXController shadow;
 
    private int m_NextAction;
    public int nextAction
    {
        get
        {
            if (m_Animator)
            {
                m_NextAction = m_Animator.GetInteger(GAStaticDefine.Param_Action);
            }
            return m_NextAction;
        }
        set
        {
            m_NextAction = value;
            if (m_Animator)
            {
                m_Animator.SetInteger(GAStaticDefine.Param_Action, value);
            }
        }
    }
 
    public ShowActor(int npcID, int index, int instanceid, ActorShowConfig _actorShowConfig)
    {
        this.m_NpcId = npcID;
        this.m_Index = index;
        this.m_Instance = instanceid;
 
        if (npcId == 1)
        {
            Appear(index, _actorShowConfig);
        }
        else
        {
            m_NpcCfg = NPCConfig.Get(npcID);
            Appear(index, _actorShowConfig);
        }
        
    }
 
    public void Appear(int index, ActorShowConfig _actorShowConfig)
    {
        this.m_Index = index;
        this.actorShowModel = _actorShowConfig;
        if (m_Model == null)
        {
            if (npcId != 1)
            {
                m_Model = GameObjectPoolManager.Instance.RequestNpcGameObject(m_NpcId);
                m_Animator = m_Model.AddMissingComponent<Animator>();
                m_CacheLayer = m_Model.layer;
                m_Model.gameObject.SetLayer(LayerUtility.BossShow, true);
            }
            else
            {
                var hero = PlayerDatas.Instance.hero;
                m_Model = GameObject.Instantiate(hero.ClothedModel) as GameObject;
                m_Animator = m_Model.AddMissingComponent<Animator>();
                m_CacheLayer = m_Model.layer;
                m_Model.gameObject.SetLayer(LayerUtility.BossShow, true);
            }
        }
        m_Model.SetActive(true);
        m_Model.transform.position = new Vector3((float)actorShowModel.PosX[m_Index] / 200, 0, (float)actorShowModel.PosY[m_Index] / 200);
        m_CacheScale = m_Model.transform.localScale;
        m_Model.transform.localScale = Vector3.one * ((float)actorShowModel.scale[m_Index] / 100);
 
        RaycastHit _hit;
        var _heightPos = m_Model.transform.position;
        if (actorShowModel.Height.Length > 1 && m_Index == 0)
        {
            _heightPos.x = (float)actorShowModel.Height[0] / 200;
            _heightPos.y = 0;
            _heightPos.z = (float)actorShowModel.Height[1] / 200;
        }
        Ray _ray = new Ray(_heightPos + new Vector3(0, 100f, 0), Vector3.down);
        if (Physics.Raycast(_ray, out _hit, 100f, LayerUtility.WalkbleMask))
        {
            m_Model.transform.position = m_Model.transform.position.SetY(_hit.point.y);
        }
 
        m_Model.transform.rotation = MathUtility.GetClientRotationFromAngle(actorShowModel.NpcFace[m_Index]);
        RuntimeAnimatorController controller = null;
        if (npcId == 1)
        {
            var job = PlayerDatas.Instance.baseData.Job;
            var _controllerName = "A_Zs";
            if (job == 2)
            {
                _controllerName = "A_Fs";
            }
            controller = AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerShowSuffix, _controllerName);
        }
        else
        {
            controller = AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerShowSuffix, actorShowModel.mob[m_Index]);
        }
        if (controller != null)
        {
            m_CacheAnimator = m_Animator.runtimeAnimatorController;
            m_Animator.runtimeAnimatorController = controller;
            m_Animator.SetInteger(GAStaticDefine.Param_ActorInstID, m_Instance);
            if (m_Animator != null)
            {
                m_Animator.enabled = true;
                if (m_Index < actorShowModel.clipActions.Length)
                {
                    nextAction = actorShowModel.clipActions[m_Index];
                }
                else
                {
                    nextAction = GAStaticDefine.Act_Show;
                }
                m_Animator.Update(0);
            }
        }
        else
        {
            if (m_Animator != null)
            {
                m_Animator.enabled = true;
                nextAction = 0;
            }
        }
 
        if (actorShowModel.effect != null && m_Index < actorShowModel.effect.Length
            && actorShowModel.effect[m_Index] != 0)
        {
            sfxController = SFXPlayUtility.Instance.Play(actorShowModel.effect[m_Index], m_Model.transform);
            if (sfxController != null)
            {
                m_CacheEffectLayer = sfxController.gameObject.layer;
                sfxController.duration = 0;
                var _animNodde = sfxController.GetComponent<Animator>("Animation");
                if (_animNodde)
                {
                    if (_animNodde.HasState(0, GAStaticDefine.State_IdleHash))
                    {
                        _animNodde.Play(GAStaticDefine.State_IdleHash);
                    }
                }
                LayerUtility.SetLayer(sfxController.gameObject, LayerUtility.BossShow, true);
            }
        }
        RequestCircleShadow();
        if (shadow && m_NpcId != 1)
        {
            shadow.transform.localScale = m_NpcCfg.IsBoss == 1 ? Vector3.one * 3 : Vector3.one;
            shadow.gameObject.SetLayer(LayerUtility.BossShow, true);
        }
    }
 
    public void RequestCircleShadow()
    {
        RecyleCircleShadow();
        if (shadow == null && actorShowModel.shadow == 1)
        {
            shadow = SFXPlayUtility.Instance.PlayBattleEffect(999999, m_Model.transform.position, Vector3.forward);
            shadow.duration = 0;
            shadow.transform.eulerAngles = new Vector3(0, 0, 0);
        }
    }
 
    public void RecyleCircleShadow()
    {
        if (shadow)
        {
            SFXPlayUtility.Instance.Release(shadow);
            shadow = null;
        }
    }
 
    public void Disappear()
    {
        if (m_Animator != null)
        {
            m_Animator.Play(Animator.StringToHash("Idle"), 0, 0);
            m_Animator.enabled = false;
 
            if (m_CacheAnimator)
            {
                m_Animator.runtimeAnimatorController = m_CacheAnimator;
                m_CacheAnimator = null;
            }
        }
        if (m_Model != null)
        {
            m_Model.transform.localScale = m_CacheScale;
            m_Model.SetLayer(m_CacheLayer, true);
            GameObject _prefab = InstanceResourcesLoader.LoadNpcPrefab(m_NpcId);
            GameObjectPoolManager.Instance.ReleaseGameObject(_prefab, m_Model);
            m_Model = null;
        }
 
        if (sfxController != null)
        {
            sfxController.gameObject.SetLayer(m_CacheEffectLayer, true);
            SFXPlayUtility.Instance.Release(sfxController);
            sfxController = null;
        }
 
        RecyleCircleShadow();
    }
 
    public void Destroy()
    {
        if (m_Model != null)
        {
            GameObject.Destroy(m_Model);
            m_Model = null;
        }
        if (sfxController != null)
        {
            SFXPlayUtility.Instance.Release(sfxController);
            sfxController = null;
        }
        RecyleCircleShadow();
    }
}