| | |
| | | |
| | | return currentTrackEntry; |
| | | } |
| | | |
| | | public Spine.TrackEntry PlaySkillAnimation(SkillConfig skillConfig, Action onComplete = null, Action onBeginPhaseEnd = null, Action onActivePhaseEnd = null) |
| | | { |
| | | if (skillConfig == null) |
| | | { |
| | | Debug.LogError("技能配置为空,无法播放技能动画"); |
| | | return null; |
| | | } |
| | | |
| | | return PlayAnimation(skillConfig.SkillMotionName, skillConfig.StartupFrames, skillConfig.ActiveFrames, skillConfig.LoopCount, |
| | | onComplete, onBeginPhaseEnd, onActivePhaseEnd); |
| | | } |
| | | |
| | | public virtual Spine.TrackEntry PlayAnimation( |
| | | string animationName, |
| | | int loopBeginFrame, |
| | | int loopEndFrame, |
| | | int loopTimes, |
| | | Action _onComplete = null, |
| | | Action onBeginPhaseEnd = null, // 前摇结束回调 |
| | | Action onActivePhaseEnd = null // 中摇结束回调 |
| | | ) |
| | | { |
| | | if (spineAnimationState == null || skeleton == null) return null; |
| | | |
| | | var anim = skeleton.Data.FindAnimation(animationName); |
| | | if (anim == null) return null; |
| | | |
| | | float fps = BattleConst.skillMotionFps; |
| | | float beginTime = loopBeginFrame / fps; |
| | | float endTime = loopEndFrame / fps; |
| | | |
| | | currentTrackEntry = spineAnimationState.SetAnimation(0, anim, false); |
| | | |
| | | int curLoop = 0; |
| | | bool finished = false; |
| | | bool beginPhaseTriggered = false; |
| | | |
| | | Spine.Unity.UpdateBonesDelegate updateLocalHandler = null; |
| | | updateLocalHandler = (ISkeletonAnimation animated) => |
| | | { |
| | | if (finished) return; |
| | | var entry = currentTrackEntry; |
| | | if (entry == null || entry.Animation != anim) |
| | | { |
| | | skeletonGraphic.UpdateLocal -= updateLocalHandler; |
| | | return; |
| | | } |
| | | |
| | | // 前摇结束(只触发一次) |
| | | if (!beginPhaseTriggered && entry.TrackTime >= beginTime) |
| | | { |
| | | beginPhaseTriggered = true; |
| | | onBeginPhaseEnd?.Invoke(); |
| | | } |
| | | |
| | | // 中摇结束(每次到endTime都触发) |
| | | if (entry.TrackTime >= endTime) |
| | | { |
| | | onActivePhaseEnd?.Invoke(); |
| | | |
| | | curLoop++; |
| | | if (curLoop >= loopTimes) |
| | | { |
| | | finished = true; |
| | | skeletonGraphic.UpdateLocal -= updateLocalHandler; |
| | | _onComplete?.Invoke(); |
| | | return; |
| | | } |
| | | entry.TrackTime = beginTime; |
| | | beginPhaseTriggered = false; // 重置,下一轮前摇可再次触发 |
| | | } |
| | | }; |
| | | skeletonGraphic.UpdateLocal += updateLocalHandler; |
| | | |
| | | if (_onComplete != null && currentTrackEntry != null) |
| | | { |
| | | trackEntryCompleteDict[currentTrackEntry] = _onComplete; |
| | | } |
| | | |
| | | return currentTrackEntry; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | |
| | | trackEntryCompleteDict.Remove(trackEntry); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public void Test(string animationName, int beginFrame, int activeFrame, int endFrame, int activeFrameLoopCount) |
| | | { |
| | | // 要处理前摇beginFrame 后摇endFrame 中摇activeFrame |
| | | |
| | | // 中摇是有多次的activeFrameLoopCount |
| | | |
| | | var state = spineAnimationState; |
| | | var anim = skeleton.Data.FindAnimation(animationName); |
| | | |
| | | // 设定你要循环的区间(单位:秒) |
| | | float loopStart = 0.5f; |
| | | float loopEnd = 1.2f; |
| | | |
| | | // 播放动画 |
| | | state.SetAnimation(0, anim, true); |
| | | // state.GetCurrent(0).TrackTime = loopStart; |
| | | |
| | | int curFrame = 0; |
| | | |
| | | skeletonGraphic.UpdateLocal += (skeletonAnim) => |
| | | { |
| | | // if (curFrame == beginFrame) |
| | | // { |
| | | // OnBeginFrame?.Invoke(); |
| | | // } |
| | | // else if (curFrame == activeFrame) |
| | | // { |
| | | // OnActiveFrame?.Invoke(); |
| | | // } |
| | | // else if (curFrame == endFrame) |
| | | // { |
| | | // OnEndFrame?.Invoke(); |
| | | // } |
| | | // var trackEntry = state.GetCurrent(0); |
| | | // if (trackEntry != null && trackEntry.Animation == anim) |
| | | // { |
| | | // if (trackEntry.TrackTime > loopEnd) |
| | | // { |
| | | // // 回到loopStart,实现区间循环 |
| | | // trackEntry.TrackTime = loopStart; |
| | | // } |
| | | // } |
| | | }; |
| | | } |
| | | |
| | | |
| | | public virtual void Run() |
| | | { |