少年修仙传客户端代码仓库
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
using Snxxz.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 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;
 
        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)
        {
            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);
        }
        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)
        {
            _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]);
        var 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;
                m_Animator.Play(Animator.StringToHash("Show"), 0, 0);
                nextAction = GAStaticDefine.Act_Show;
            }
        }
        else
        {
            if (m_Animator != null)
            {
                m_Animator.enabled = true;
                nextAction = 0;
            }
        }
 
        if (actorShowModel.effect != 0)
        {
            sfxController = SFXPlayUtility.Instance.Play(actorShowModel.effect, m_Model.transform);
            if (sfxController != null)
            {
                sfxController.duration = 0;
            }
        }
        RequestCircleShadow();
        if (shadow)
        {
            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.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)
        {
            SFXPlayUtility.Instance.Release(sfxController);
            sfxController = null;
        }
 
        RecyleCircleShadow();
    }
}