Explorar o código

修改技能动作结束直接衔接idle动作,不需要等待status变化,以免造成动作卡顿表现

大爷 hai 1 ano
pai
achega
127ca8384c

+ 22 - 3
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/UnitRenderSystem.cs

@@ -4,6 +4,7 @@ using UnityEngine;
 using System.Text.RegularExpressions;
 using ET.EventType;
 using Sirenix.Utilities;
+using CommonAI.Zone;
 
 namespace ET.Client
 {
@@ -121,7 +122,7 @@ namespace ET.Client
                 var cmd = self.FilterCmdList();
                 if (cmd != null)
                 {
-                    if (self.DoingCmd?.Type != cmd.Type || cmd.Type >= AniType.Skill0)
+                    if (self.DoingCmd?.Type != cmd.Type || cmd.IsSkillCmd())
                     {
                         self.ExeCommand(cmd);
                     }
@@ -153,9 +154,27 @@ namespace ET.Client
         //执行指令
         private static void ExeCommand(this UnitRenderComponet self, AnimatorCommand cmd)
         {
-            Log.Debug($"{self.GameObject.name} play ani:{cmd.Type}");
             self.DoingCmd = (AnimatorCommand)cmd;
-            self.AniData.PlayAnimation(cmd.Type);
+
+            if(!cmd.IsSkillCmd())
+            {
+                self.AniData.PlayAnimation(cmd.Type);
+            }
+            else
+            {
+                //Skill动作和实际技能时间不太匹配,切到idle动作
+                self.AniData.PlayAnimation(cmd.Type, () => {
+                    if (self.DoingCmd == cmd)
+                    {
+                        Log.Debug($"{cmd.Type} finish early, to idle");
+                        self.ExeCommand(UnitRenderComponet.CMDIdle);
+                    }
+                    else
+                    {
+                        Log.Debug($"ani change to other: {self.DoingCmd.Type}");
+                    }
+                });
+            }
         }
 
         //从指令队列中分析出当前需要执行的指令

+ 8 - 3
Unity/Assets/Scripts/Codes/ModelView/Client/Unit/UnitRenderComponet.cs

@@ -7,8 +7,8 @@ namespace ET.Client
     [ChildOf(typeof(ModelViewComponent))]
 	public class UnitRenderComponet : Entity, IAwake<GameObject>, IUpdate, IDestroy
 	{
-        public static readonly AnimatorCommand CMDIdle = new AnimatorCommand(AniType.Idle);
-        public static readonly AnimatorCommand CMDRun = new AnimatorCommand(AniType.Run);
+        public static readonly AnimatorCommand CMDIdle = new AnimatorCommand(AniType.Idle, true);
+        public static readonly AnimatorCommand CMDRun = new AnimatorCommand(AniType.Run, true);
         public static readonly AnimatorCommand CMDDead = new AnimatorCommand(AniType.Dead);
 
         //指令队列
@@ -33,9 +33,14 @@ namespace ET.Client
         public float Speed = 1.0f;
         public uint GroupId = 0;
         public bool Loop = false;
-        public AnimatorCommand(AniType type)
+        public AnimatorCommand(AniType type, bool loop = false)
         {
             this.Type = type;
+            this.Loop = loop;
+        }
+        public bool IsSkillCmd()
+        {
+            return Type >= AniType.Skill0 && Type < AniType.SkillMax;
         }
     }
 }

+ 30 - 9
Unity/Assets/Scripts/Codes/Mono/AnimationData.cs

@@ -33,6 +33,32 @@ namespace Mono
         }
 
         public AniInfo[] AnimationClips = new AniInfo[1];
+        private Action aniEndcb;
+        private AnimancerState notifyState;
+
+        private void Awake ()
+        {
+            aniEndcb = null;
+            foreach (var clip in AnimationClips)
+            {
+                if (clip.Type >= AnimationType.Skill0 && clip.Type < AnimationType.SkillMax)
+                {
+                    clip.Clip.Events.OnEnd = SkillEndCB;
+                }
+            }
+        }
+
+        protected void SkillEndCB()
+        {
+            if(notifyState != null /*&& notifyState.IsPlaying*/)
+            {
+                notifyState.Events = null;
+                notifyState = null;
+            }
+            Action tocall = aniEndcb;
+            aniEndcb = null;
+            tocall?.Invoke();
+        }
 
         public ClipTransition GetClip(AnimationType type)
         {
@@ -45,25 +71,20 @@ namespace Mono
             }
             return null;
         }
+
         public void PlayAnimation(AnimationType type, Action endcb = null)
         {
+            Log.Debug($"{this.gameObject.name} toplay ani:{type}");
+            aniEndcb = endcb;
             var clip = GetClip(type);
             if (clip != null)
             {
-                //Log.Debug($"Play ani:{type}");
-                var state = Animancer.Play(clip);
-                state.Time = 0;
-                if(endcb != null)
-                {
-                    state.Events.OnEnd = endcb;
-                }
+                notifyState = Animancer.Play(clip, 0.1f, FadeMode.FromStart);
             }
             else
             {
                 Log.Error($"Not exist clip({type}) @{gameObject.name}");
             }
         }
-
-
     }
 }