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);
|
}
|
}
|
}
|