private bool PlayScriptAnimation(string animCode, Action callback = null, float fadeDuration = 0f) { var animancer = GetAnimancer(); if (animCode.StartsWith("@")) { string path = animCode.TrimStart('@'); //load and play AnimationClip Addressables.LoadAssetAsync <AnimationClip>(path).Completed += r => { var clip = r.Result; //检查动作配置是否正确 if (clip.isLooping && callback != null) { Debug.LogError($"动作设置了LOOP但是会有回调!请检查{path}"); } else if (!clip.isLooping && callback == null) { Debug.LogError($"动作没设置LOOP但是没有回调!请检查{path}"); } var state = animancer.Play(clip); //callback if needed if (callback != null) { if (fadeDuration > 0) { GameUtil.CallWithDelay(state.Duration - fadeDuration, callback); } else { state.Events.OnEnd = () => { state.Stop(); callback(); }; } } }; return(true); } else { //animancer.Stop(); //force switch to AnimationController animancer.PlayController(); //fade to AnimationController return(false); } }
/// <summary> /// 播放 /// </summary> /// <param name="forceChangeWeapon">是否强行更换武器,一般仅用于技能编辑时看效果</param> public void Play(Action callback = null) { var display = GetDisplay(); if (display == null) { Debug.LogError($"招式{Zhaoshi.Key}没有配置Display!"); if (callback != null) { callback(); } return; } if (Source != null) { Source.CurDisplay = display; GameUtil.CallWithDelay(display.AnimaionDelay, Source.Attack); } //普通特效 if (!string.IsNullOrEmpty(display.CastEft)) { GameUtil.CallWithDelay(display.CastDelay, DisplayCastEft); } //格子特效 if (!string.IsNullOrEmpty(display.BlockEft)) { GameUtil.CallWithDelay(display.BlockDelay, DisplayBlockEft); } //音效 if (!string.IsNullOrEmpty(display.AudioEft)) { GameUtil.CallWithDelay(display.AudioEftDelay, ExecuteSoundEffect); } //播放受击动画和飘字 GameUtil.CallWithDelay(display.HitDelay, ExecuteBeHit); //回调 if (callback != null) { GameUtil.CallWithDelay(display.Duration, callback); } }