Browse Source

整理代码:事件相关Type就放在事件类里面,干净又卫生

大爷 1 year ago
parent
commit
0e5bfd6a8c

+ 7 - 7
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleUnit.cs

@@ -31,13 +31,13 @@ public class BattleUnit : BattleObject
         zu.OnMaxMPChanged += (ZoneUnit unit, int oldMaxMP, int newMaxMP)=> { };
         zu.OnLaunchSkill += OnLaunchSkill;
         zu.OnBuffAdded += (ZoneUnit unit, ZoneUnit.BuffState buff) => {
-            EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(Id, buff, BuffChangeType.Add));
+            EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(Id, buff, BuffChangeEvent.BuffOP.Add));
         };
         zu.OnBuffRemoved += (ZoneUnit unit, ZoneUnit.BuffState buff) => {
-            EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(Id, buff, BuffChangeType.Remove));
+            EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(Id, buff, BuffChangeEvent.BuffOP.Remove));
         };
         zu.OnBuffChanged += (ZoneUnit unit, ZoneUnit.BuffState buff) => {
-            EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(Id, buff, BuffChangeType.Change));
+            EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(Id, buff, BuffChangeEvent.BuffOP.Change));
         };
         zu.OnRemoveBuffByOverlayLevel += (ZoneUnit unit, ZoneUnit.BuffState buff) => { };
         zu.OnActionSubStatusChanged += OnActionSubStatusChanged;
@@ -77,7 +77,7 @@ public class BattleUnit : BattleObject
             var duration = action.ActionTimeArray != null ? action.ActionTimeArray[0] : actdata.TotalTimeMS;
             EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(
                 Id,
-                AnimatorEventType.Skill,
+                PlayAnimatorEvent.AniType.Skill,
                 actdata.ActionName,
                 duration,
                 action.ActionSpeed,
@@ -109,7 +109,7 @@ public class BattleUnit : BattleObject
 
                 EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(
                     Id,
-                    AnimatorEventType.Skill,
+                    PlayAnimatorEvent.AniType.Skill,
                     item.ActionName,
                     action.ActionTimeArray[i],
                     speed, GroupId(),
@@ -169,11 +169,11 @@ public class BattleUnit : BattleObject
     private void registerActionHandler()
     {
         actionChangeHandler.AddListener(UnitActionStatus.Idle, (_) => {
-            EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(Id, AnimatorEventType.Idle));
+            EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(Id, PlayAnimatorEvent.AniType.Idle));
         });
 
         var move = actionChangeHandler.AddListener(UnitActionStatus.Move, (o) => {
-            EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(Id, AnimatorEventType.Run));
+            EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(Id, PlayAnimatorEvent.AniType.Run));
         });
         actionChangeHandler.AddListener(UnitActionStatus.Chaos, move);
         actionChangeHandler.AddListener(UnitActionStatus.ServerSyncMove, move);

+ 4 - 4
Unity/Assets/Scripts/Codes/HotfixView/Client/Effect/BuffEffectMgr.cs

@@ -27,7 +27,7 @@ namespace ET.Client
 
             //Log.Debug($"Buff({args.Buff?.BuffID}) {args.Type} @{unit.ZUnit.TemplateID}");
 
-            if (args.Type == BuffChangeType.Add)
+            if (args.Type == EventType.BuffChangeEvent.BuffOP.Add)
             {
                 BuffTemplate bt = args.Buff.Data;
                 if (bt.MakeAvatar)
@@ -37,12 +37,12 @@ namespace ET.Client
                 }
                 AddBuff(args.Buff, unitRender, unit).Coroutine();
             }
-            else if (args.Type == BuffChangeType.Remove)
+            else if (args.Type == EventType.BuffChangeEvent.BuffOP.Remove)
             {
                 BuffTemplate bt = args.Buff.Data;
                 RemoveBuff(bt, unitRender);
             }
-            else if (args.Type == BuffChangeType.Change)
+            else if (args.Type == EventType.BuffChangeEvent.BuffOP.Change)
             {
                 BuffTemplate bt = args.Buff.Data;
                 //随BUFF状态变更,表现特效不同时.
@@ -58,7 +58,7 @@ namespace ET.Client
                     }
                 }
             }
-            else if (args.Type == BuffChangeType.Reload)
+            else if (args.Type == EventType.BuffChangeEvent.BuffOP.Reload)
             {
                 var list = unit.ZUnit.AllBuffs;
                 list.ForEach((CommonAI.ZoneClient.ZoneUnit.BuffState buff) =>

+ 4 - 4
Unity/Assets/Scripts/Codes/HotfixView/Client/Unit/OnNewZoneObject.cs

@@ -63,20 +63,20 @@ namespace ET.Client
             switch(zu.CurrentState)
             {
                 case CommonAI.Zone.Helper.UnitActionStatus.Move:
-                    EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(zu.ObjectID, AnimatorEventType.Run));
+                    EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(zu.ObjectID, PlayAnimatorEvent.AniType.Run));
                     break;
                 case CommonAI.Zone.Helper.UnitActionStatus.Dead:
-                    EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(zu.ObjectID, AnimatorEventType.Dead));
+                    EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(zu.ObjectID, PlayAnimatorEvent.AniType.Dead));
                     break;
                 case CommonAI.Zone.Helper.UnitActionStatus.Stun:
                 case CommonAI.Zone.Helper.UnitActionStatus.Damage:
                 default:
-                    EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(zu.ObjectID, AnimatorEventType.Idle));
+                    EventSystem.Instance.Publish(PlayAnimatorEvent.Clone(zu.ObjectID, PlayAnimatorEvent.AniType.Idle));
                     break;
             }
             if(zu.GetBuffStatusCount() > 0)
             {
-                EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(zu.ObjectID, null, BuffChangeType.Reload));
+                EventSystem.Instance.Publish(BuffChangeEvent.Static.Clone(zu.ObjectID, null, EventType.BuffChangeEvent.BuffOP.Reload));
             }
         }
 

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

@@ -1,5 +1,5 @@
-using CMDType = ET.AnimatorEventType;
-using AniType = Mono.AnimationData.AnimationType;
+using CMDType = ET.EventType.PlayAnimatorEvent.AniType;
+using AnimationType = Mono.AnimationData.AnimationType;
 using UnityEngine;
 using System.Text.RegularExpressions;
 using ET.EventType;
@@ -36,9 +36,9 @@ namespace ET.Client
                 if (m.Success)
                 {
                     int n = System.Convert.ToInt32(m.Groups[1].Value, 10);
-                    if (n >= 0 && AniType.SkillMax > AniType.Skill0 + n)
+                    if (n >= 0 && AnimationType.SkillMax > AnimationType.Skill0 + n)
                     {
-                        AnimatorCommand cmd = new AnimatorCommand((AniType)(AniType.Skill0 + n))
+                        AnimatorCommand cmd = new AnimatorCommand(AnimationType.Skill0 + n)
                         {
                             Duration = args.Duration,
                             Speed = args.Speed,
@@ -55,9 +55,9 @@ namespace ET.Client
             {
                 AnimatorCommand cmd = args.CommandType switch
                 {
-                    AnimatorEventType.Idle => UnitRenderComponet.CMDIdle,
-                    AnimatorEventType.Run => UnitRenderComponet.CMDRun,
-                    AnimatorEventType.Dead => UnitRenderComponet.CMDDead,
+                    PlayAnimatorEvent.AniType.Idle => UnitRenderComponet.CMDIdle,
+                    PlayAnimatorEvent.AniType.Run => UnitRenderComponet.CMDRun,
+                    PlayAnimatorEvent.AniType.Dead => UnitRenderComponet.CMDDead,
                     _ => UnitRenderComponet.CMDIdle
                 };
                 component.AppendCommand(cmd);
@@ -199,7 +199,7 @@ namespace ET.Client
         private static void ExeCommand(this UnitRenderComponet self, AnimatorCommand cmd)
         {
             self.DoingCmd = (AnimatorCommand)cmd;
-            if(self.AniData.IsPauseStatus() && cmd.Type == AniType.Dead)
+            if(self.AniData.IsPauseStatus() && cmd.Type == AnimationType.Dead)
             {
                 self.AniData.Resume();
             }

+ 33 - 30
Unity/Assets/Scripts/Codes/Model/Client/EventTypeClient.cs

@@ -47,7 +47,6 @@ namespace ET
             }
         }
 
-
         public class OnNewZoneObject
         {
             public uint ObjectId;
@@ -74,8 +73,15 @@ namespace ET
         }
         public class PlayAnimatorEvent
         {
+            public enum AniType
+            {
+                Idle = 0,
+                Run,
+                Skill,
+                Dead
+            }
             public uint UnitId;
-            public AnimatorEventType CommandType;
+            public AniType CommandType;
             public string SkillName;
             public float Duration;
             public float Speed;
@@ -84,7 +90,7 @@ namespace ET
             public string Audio;
 
             public static PlayAnimatorEvent Static = new PlayAnimatorEvent();
-            public static PlayAnimatorEvent Clone(uint id, AnimatorEventType type, string skill = "", float duration = -1, float speed = 1.0f, uint gid = 0, bool loop = false, string audio = "")
+            public static PlayAnimatorEvent Clone(uint id, AniType type, string skill = "", float duration = -1, float speed = 1.0f, uint gid = 0, bool loop = false, string audio = "")
             {
                 Static.UnitId = id;
                 Static.CommandType = type;
@@ -214,11 +220,18 @@ namespace ET
         }
         public class BuffChangeEvent
         {
+            public enum BuffOP
+            {
+                Add,
+                Remove,
+                Change,
+                Reload, //模型刚加载完,buff效果重新加载
+            }
             public uint ObjectId;
             public CommonAI.ZoneClient.ZoneUnit.BuffState Buff;
-            public BuffChangeType Type;
+            public BuffOP Type;
             public static BuffChangeEvent Static = new();
-            public BuffChangeEvent Clone(uint id, CommonAI.ZoneClient.ZoneUnit.BuffState buff, BuffChangeType type)
+            public BuffChangeEvent Clone(uint id, CommonAI.ZoneClient.ZoneUnit.BuffState buff, BuffOP type)
             {
                 ObjectId = id;
                 Buff = buff;
@@ -248,34 +261,24 @@ namespace ET
                 return this;
             }
         }
-
-        public class BattleMsgEvent
+        public class ShowHUDEvent { }
+        public class ShowUIAnimation
         {
-            public string msg;
-            public static BattleMsgEvent Static = new();
-            public BattleMsgEvent Clone(string m)
+            public enum AniType
             {
-                msg = m;
-                return this;
+                Gift,
+                Monster,
+                Tower
+            }
+            public AniType Type;
+            public int Param1;
+            public static ShowUIAnimation Static = new();
+            public static ShowUIAnimation Clone(AniType type, int param1)
+            {
+                Static.Type = type;
+                Static.Param1 = param1;
+                return Static;
             }
         }
-        public class ShowHUDEvent { }
-    }
-
-    //状态指令
-    public enum AnimatorEventType
-    {
-        Idle = 0,
-        Run,
-        Skill,
-        Dead
-    }
-
-    public enum BuffChangeType
-    {
-        Add,
-        Remove,
-        Change,
-        Reload, //模型刚加载完,buff效果重新加载
     }
 }

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

@@ -1,7 +1,7 @@
 using UnityEngine;
 using Mono;
 using System.Collections.Generic;
-using AniType = Mono.AnimationData.AnimationType;
+using AnimationType = Mono.AnimationData.AnimationType;
 using FairyGUI;
 using CommonLang;
 
@@ -10,9 +10,9 @@ namespace ET.Client
     [ChildOf(typeof(ModelViewComponent))]
 	public class UnitRenderComponet : Entity, IAwake<GameObject>, IUpdate, IDestroy
 	{
-        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);
+        public static readonly AnimatorCommand CMDIdle = new AnimatorCommand(AnimationType.Idle, true);
+        public static readonly AnimatorCommand CMDRun = new AnimatorCommand(AnimationType.Run, true);
+        public static readonly AnimatorCommand CMDDead = new AnimatorCommand(AnimationType.Dead);
 
         //buff产生的特效.
         public HashMap<string, uint> BuffEffects = new();
@@ -104,19 +104,19 @@ namespace ET.Client
     //TODO: 支持ObjectPool
     public class AnimatorCommand
     {
-        public AniType Type;
+        public AnimationType Type;
         public float Duration = -1f;
         public float Speed = 1.0f;
         public uint GroupId = 0;
         public bool Loop = false;
-        public AnimatorCommand(AniType type, bool loop = false)
+        public AnimatorCommand(AnimationType type, bool loop = false)
         {
             this.Type = type;
             this.Loop = loop;
         }
         public bool IsSkillCmd()
         {
-            return Type >= AniType.Skill0 && Type < AniType.SkillMax;
+            return Type >= AnimationType.Skill0 && Type < AnimationType.SkillMax;
         }
     }
 }