| | |
| | | |
| | | public static List<string> AttackMotionList = new List<string> |
| | | { |
| | | MotionName.attack.ToString(), |
| | | MotionName.angerSkill.ToString(), |
| | | MotionName.passiveSkill.ToString(), |
| | | MotionName.attack.ToString().ToLower(), |
| | | MotionName.angerSkill.ToString().ToLower(), |
| | | MotionName.passiveSkill.ToString().ToLower(), |
| | | }; |
| | | |
| | | private Dictionary<Spine.TrackEntry, Action> trackEntryCompleteDict = new Dictionary<Spine.TrackEntry, Action>(); |
| | |
| | | // 动画事件 |
| | | public Action OnAttackAnimationComplete; |
| | | public Action OnHitAnimationComplete; |
| | | public Action<MotionName> onAnimationComplete; |
| | | public Action<string> onAnimationComplete; |
| | | |
| | | #region 组件引用 |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | // 获取动画 |
| | | |
| | | Spine.Animation anim = skeleton.Data.FindAnimation(skillConfig.SkillMotionName); |
| | | |
| | | if (null == anim) |
| | | { |
| | | for (int i = 0; i < skeleton.Data.Animations.Count; i++) |
| | | { |
| | | var skeletonAnim = skeleton.Data.Animations.Items[i]; |
| | | if (skeletonAnim.Name.ToLower() == skillConfig.SkillMotionName.ToLower()) |
| | | { |
| | | anim = skeletonAnim; |
| | | // 找到动画 |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 获取动画 |
| | | if (anim == null) |
| | | { |
| | | BattleDebug.LogError($"找不到动画: {skillConfig.SkillMotionName}"); |
| | |
| | | /// </summary> |
| | | protected virtual void OnAnimationComplete(Spine.TrackEntry trackEntry) |
| | | { |
| | | string animation = trackEntry.Animation.Name; |
| | | string animation = trackEntry.Animation.Name.ToLower(); |
| | | |
| | | // 攻击动画完成后恢复到待机状态 |
| | | if (AttackMotionList.Contains(animation)) |
| | |
| | | PlayAnimation(MotionName.idle, true); |
| | | } |
| | | // 受伤动画完成后恢复到待机状态 可能触发多次 因为有多段攻击的存在 |
| | | else if (animation == MotionName.hit.ToString()) |
| | | else if (animation == MotionName.hit.ToString().ToLower()) |
| | | { |
| | | OnHitAnimationComplete?.Invoke(); |
| | | PlayAnimation(MotionName.idle, true); |
| | | } |
| | | onAnimationComplete?.Invoke((MotionName)Enum.Parse(typeof(MotionName), animation)); |
| | | |
| | | onAnimationComplete?.Invoke(animation); |
| | | |
| | | // 只调用本次TrackEntry的回调 |
| | | if (trackEntryCompleteDict.TryGetValue(trackEntry, out var cb)) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | 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() |