using CMDType = ET.Client.AnimatorComponent.CommandType; using AniType = Mono.AnimationData.AnimationType; namespace ET.Client { [FriendOfAttribute(typeof(GameObjectComponent))] [FriendOf(typeof(AnimatorComponent))] public static class AnimatorComponentSystem { [ObjectSystem] public class AnimatorComponentAwakeSystem : AwakeSystem { protected override void Awake(AnimatorComponent self) { self.Awake(); } } [ObjectSystem] public class AnimatorComponentUpdateSystem : UpdateSystem { protected override void Update(AnimatorComponent self) { self.Update(); } } [ObjectSystem] public class AnimatorComponentDestroySystem : DestroySystem { protected override void Destroy(AnimatorComponent self) { self.AniData.Animancer.Stop(); } } //===AnimatorComponent 扩展方法------- public static void AppendCommand(this AnimatorComponent self, CMDType type) { self.Commands.Add(new AnimatorComponent.Command(type)); } public static void AppendCommand(this AnimatorComponent self, AnimatorComponent.Command cmd) { self.Commands.Add(cmd); } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ public static void Awake(this AnimatorComponent self) { GameObjectComponent gameObjectComponent = self.GetParent().GetComponent(); self.AniData = gameObjectComponent.GameObject.GetComponent(); self.DoingType = AniType.Dead; self.ExeCommand(AnimatorComponent.CMDIdle); } public static void Update(this AnimatorComponent self) { self.ExeCommand(self.FilterCmdList()); } //执行指令 private static void ExeCommand(this AnimatorComponent self, AnimatorComponent.Command? cmd) { if (cmd == null) return; var ani = cmd?.Type switch { CMDType.Idle => AniType.Idle, CMDType.Run => AniType.Run, CMDType.StopRun => AniType.Idle, CMDType.StopSkill => AniType.Idle, CMDType.Skill0 => AniType.Skill0, CMDType.Skill1 => AniType.Skill1, CMDType.Skill2 => AniType.Skill2, CMDType.Skill3 => AniType.Skill3, CMDType.Dead => AniType.Dead, _ => AniType.Idle }; if (self.DoingType == ani) return; self.DoingType = ani; self.AniData.PlayAnimation(ani, () => { self.DoingType = AniType.Idle; self.AniData.PlayAnimation(AniType.Idle); }); } //从指令队列中分析出当前需要执行的指令 private static AnimatorComponent.Command? FilterCmdList(this AnimatorComponent self) { var cmds = self.Commands; if (cmds.Count <= 0) { return null; } var cmd = cmds[0]; for(var i=1; i= CMDType.Skill0 && cmd.Type <= CMDType.Skill3) { cmd = AnimatorComponent.CMDIdle; } else if(next.Type > cmd.Type && cmd.Type < CMDType.Skill0) { cmd = next; } } cmds.Clear(); return cmd; } } }