少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-13 c7f64d977c4e2884d5411a5a2d0f37b6afa52963
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Snxxz.UI;
 
 
public class STM_SkillShow : StateMachineBehaviour
{
    static int cacheSkillID;
 
    protected float m_Duration;
    protected int m_ProcessIndex;
    protected float m_ProcessFrame;
    protected Skill m_CacheSkill;
 
    protected float m_EffectAnimatorSpeed = 1;
 
    protected bool m_ClipEventPass = false;
 
    protected exAnimationClipEvent clipEvent;
 
    [SerializeField] List<exAnimationClipEvent> clipEvents;
 
    [System.Serializable]
    public class exAnimationClipEvent
    {
        public int index = -1;
        public int skillId;
        public E_FrameEventType frameEventType;
        public int intParam;
    }
 
 
    public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnStateEnter(animator, stateInfo, layerIndex);
        m_ProcessIndex = 0;
        m_ProcessFrame = 0;
        m_ClipEventPass = false;
        clipEvent = null;
        m_Duration = 0;
        var _hero = PlayerDatas.Instance.hero;
        if (_hero != null)
        {
            cacheSkillID = UI3DHeroSkillShow.Instance.cacheSkillId;
            m_CacheSkill = _hero.SkillMgr.Get(cacheSkillID);
            if (clipEvents != null)
            {
                clipEvent = clipEvents.Find((x) =>
                {
                    return x.skillId == cacheSkillID;
                });
            }
        }
    }
 
    public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnStateUpdate(animator, stateInfo, layerIndex);
 
        m_Duration += Time.deltaTime;
        m_ProcessFrame = (int)(m_Duration * 30 * animator.speed);
 
        ProcessFrameEvent(animator, stateInfo);
    }
 
    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnStateExit(animator, stateInfo, layerIndex);
    }
 
    private void ProcessFrameEvent(Animator animator, AnimatorStateInfo stateInfo)
    {
        if (clipEvent != null && clipEvent.index != -1 && m_ProcessFrame >= clipEvent.index && !m_ClipEventPass)
        {
            m_ClipEventPass = true;
            switch (clipEvent.frameEventType)
            {
                case E_FrameEventType.OnPlayEffect:
                    int _effectConfigID = clipEvent.intParam;
                    OnPlayerEffect(_effectConfigID);
                    break;
            }
        }
 
        if (m_CacheSkill.skillInfo.soFile == null)
        {
            return;
        }
        for (; m_ProcessIndex < m_CacheSkill.skillInfo.soFile.animationEventList.Count; ++m_ProcessIndex)
        {
            if (m_ProcessFrame < m_CacheSkill.skillInfo.soFile.animationEventList[m_ProcessIndex].index)
            {
                break;
            }
            switch (m_CacheSkill.skillInfo.soFile.animationEventList[m_ProcessIndex].frameEventType)
            {
                case E_FrameEventType.OnPlayEffect:
 
                    int _effectConfigID = m_CacheSkill.skillInfo.soFile.animationEventList[m_ProcessIndex].intParam;
                    OnPlayerEffect(_effectConfigID);
                    break;
                case E_FrameEventType.OnPlayAudio:
                    int _audioID = m_CacheSkill.skillInfo.soFile.animationEventList[m_ProcessIndex].intParam;
                    SoundPlayer.Instance.PlayUIAudio(_audioID);
                    break;
            }
        }
 
    }
 
    protected virtual void OnPlayerEffect(int id)
    {
        var config = EffectConfig.Get(id);
        if (config != null && config.setParent != 4)
        {
            SFXPlayUtility.Instance.PlayBattleEffect(id, UI3DHeroSkillShow.Instance.hero);
        }
    }
}