123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 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<AnimatorComponent>
- {
- protected override void Awake(AnimatorComponent self)
- {
- self.Awake();
- }
- }
- [ObjectSystem]
- public class AnimatorComponentUpdateSystem : UpdateSystem<AnimatorComponent>
- {
- protected override void Update(AnimatorComponent self)
- {
- self.Update();
- }
- }
- [ObjectSystem]
- public class AnimatorComponentDestroySystem : DestroySystem<AnimatorComponent>
- {
- 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<Unit>().GetComponent<GameObjectComponent>();
- self.AniData = gameObjectComponent.GameObject.GetComponent<Mono.AnimationData>();
- 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<cmds.Count; i++)
- {
- var next = cmds[i];
- if(next.Type == CMDType.StopRun && cmd.Type == CMDType.Run)
- {
- cmd = AnimatorComponent.CMDIdle;
- }
- else if(next.Type == CMDType.StopSkill && cmd.Type >= 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;
- }
- }
- }
|