Browse Source

修改场景、对象消息分发器,合二为一

大爷 1 year ago
parent
commit
f8e5d8e7a5

+ 32 - 34
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr.cs

@@ -16,14 +16,13 @@ namespace ET
         public ZoneLayer Layer;
 
         private readonly MemoryStream writeBuffer = new MemoryStream(2048);
-        private EventDispatcher<ZoneEvent> zoneEventHandler;
-        private EventDispatcher<ObjectEvent> objectEventHandler;
+        private EventDispatcher<Event> eventHandler;
         private static CommonLang.Geometry.Vector3 vecTemp = new();
 
         public void Awake()
         {
-            zoneEventHandler = new();
-            objectEventHandler = new();
+            eventHandler = new();
+            //eventHandler = new();
             registerEventHandler();
 
             Layer = TemplateManager.Factory.CreateClientZoneLayer(BattleResourceMgr.Instance.GameEditorTemplates, this);
@@ -32,8 +31,12 @@ namespace ET
             Layer.LayerInit += LayerEvent_Init;
             Layer.ObjectEnter += LayerEvent_ObjectEnter;
             Layer.ObjectLeave += LayerEvent_ObjectLeave;
-            Layer.MessageReceived += LayerEvent_MessageReceived;
-            Layer.DecorationChanged += LayerEvent_DecorationChanged;
+            Layer.MessageReceived += (ZoneLayer _, CommonLang.Protocol.IMessage msg) => {
+                eventHandler.Notify(msg as Event);
+            };
+            Layer.DecorationChanged += (ZoneLayer _, CommonAI.ZoneClient.ZoneEditorDecoration ed) => {
+                Log.Error("not implements: DecorationChanged");
+            };
         }
 
         public void Update(int timeMS)
@@ -138,48 +141,40 @@ namespace ET
 
         protected void LayerEvent_MessageReceived(CommonAI.ZoneClient.ZoneLayer layer, CommonLang.Protocol.IMessage msg)
         {
-            if (msg is ZoneEvent)
+            eventHandler.Notify(msg as Event);
+            /*if (msg is ZoneEvent)
             {
-                zoneEventHandler.Notify(msg as ZoneEvent);
+                
             }
             else if(msg is ObjectEvent)
             {
-                objectEventHandler.Notify(msg as ObjectEvent);
-            }
+                eventHandler.Notify(msg as ObjectEvent);
+            }*/
         }
 
         private void registerEventHandler()
         {
             //actor===================
-            objectEventHandler.AddListener<SetAutoBattleB2C>((ev) => {
+            eventHandler.AddListener<SetAutoBattleB2C>((ev) => {
                 var isAutoFight = (ev as SetAutoBattleB2C).isAutoBattle != 0;
                 Log.Debug($"AutoFight: {isAutoFight}");
 
                 (UnitMgr.Instance.Actor.ZUnit as ZoneActor).IsGuard = isAutoFight;
             });
-            objectEventHandler.AddListener<PlayerFocuseTargetEvent>((ev) =>
+            eventHandler.AddListener<PlayerFocuseTargetEvent>((ev) =>
             {
-                var e = ev as PlayerFocuseTargetEvent;
-                if(e.ObjectID == UnitMgr.Instance.ActorId)
-                {
-                    var target = UnitMgr.Instance.GetUnit(e.targetUnitID);
-                    if (target != null)
-                    {
-                        Log.Debug($"we have target: {target.Id}");
-                    }
-                }
             });
             
-            objectEventHandler.AddListener<ShowTipsEventB2C>((ev) =>
+            eventHandler.AddListener<ShowTipsEventB2C>((ev) =>
             {
             });
-            objectEventHandler.AddListener<UnitDeadEvent>((ev) =>
+            eventHandler.AddListener<UnitDeadEvent>((ev) =>
             {
             });
-            objectEventHandler.AddListener<UnitRebirthEvent>((ev) =>
+            eventHandler.AddListener<UnitRebirthEvent>((ev) =>
             {
             });
-            objectEventHandler.AddListener<UnitHitEvent>((ev) =>
+            eventHandler.AddListener<UnitHitEvent>((ev) =>
             {
                 var e = ev as UnitHitEvent;
                 var unit = UnitMgr.Instance.GetUnit(e.ObjectID);
@@ -222,22 +217,22 @@ namespace ET
                     EventSystem.Instance.Publish<PlayEffectEvent>(PlayEffectEvent.Static.Clone(hitEffect, e.ObjectID, vecTemp, 0, roation));
                 }
             });
-            objectEventHandler.AddListener<PlayerPKModeChangeEventB2C>((ev) =>
+            eventHandler.AddListener<PlayerPKModeChangeEventB2C>((ev) =>
             {
                 //TODO:替代virtual层
                 var e = ev as PlayerPKModeChangeEventB2C;
                 Log.Debug($"PKMode: {e.CurMode}");
             });
-            objectEventHandler.AddListener<PlayerBattlePropChangeEventB2C>((ev) =>
+            eventHandler.AddListener<PlayerBattlePropChangeEventB2C>((ev) =>
             {
             });
-            objectEventHandler.AddListener<PlayerPKValueChangeEventB2C>((ev) =>
+            eventHandler.AddListener<PlayerPKValueChangeEventB2C>((ev) =>
             {
             });
-            objectEventHandler.AddListener<BuffActiveSkillEventB2C>((ev) =>
+            eventHandler.AddListener<BuffActiveSkillEventB2C>((ev) =>
             {
             });
-            objectEventHandler.AddListener<UnitEffectEvent>((ev) =>
+            eventHandler.AddListener<UnitEffectEvent>((ev) =>
             {
                 var e = ev as UnitEffectEvent;
                 vecTemp.Set(0,0,0);
@@ -248,10 +243,8 @@ namespace ET
                 }
                 EventSystem.Instance.Publish<PlayEffectEvent>(PlayEffectEvent.Static.Clone(e.effect, e.ObjectID, vecTemp));
             });
-            objectEventHandler.AddListener<XmdsUnitPropEventB2C>((ev) =>
+            eventHandler.AddListener<XmdsUnitPropEventB2C>((ev) =>
             {
-                var prop = (ev as XmdsUnitPropEventB2C).Props;
-                Log.Debug($"UnitPropChange: {ev.ObjectID}");
             });
             //NPCCureEventB2C
             //MonsterSufferDamageInfoB2C
@@ -261,7 +254,12 @@ namespace ET
             //怪物归属权
             //MonsterHeirInfoChangeEventB2C
 
-            zoneEventHandler.AddListener<AddEffectEvent>((ev) => {
+            eventHandler.AddListener<CameraMoveToEvent>((ev) =>
+            {
+                var e = ev as CameraMoveToEvent;
+                EventSystem.Instance.Publish<CameraEvent>(CameraEvent.Static.Clone(e.x, e.height, e.y, e.TimeMS, e.MoveSpeedSec));
+            });
+            eventHandler.AddListener<AddEffectEvent>((ev) => {
                 var e = ev as AddEffectEvent;
                 if(e.hostId == 0 || UnitMgr.Instance.HasUnit(e.hostId))
                 {

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

@@ -172,14 +172,14 @@ public class BattleUnit : BattleObject
                 var hp = ZUnit.HP;
                 var pg = (float)ZUnit.HP * 100 / ZUnit.MaxHP;
                 EventSystem.Instance.Publish<HPRefresh>(HPRefresh.Static.Clone(HPRefresh.Index.Tower, pg, hp));
-                Log.Debug($"tower({ZUnit.ObjectID}@{ZUnit.Info.Name}) hp: {ZUnit.HP}/{ZUnit.MaxHP}");
+                //Log.Debug($"tower({ZUnit.ObjectID}@{ZUnit.Info.Name}) hp: {ZUnit.HP}/{ZUnit.MaxHP}");
             }
             else if(prop.GameStatusType == XmdsUnitProperties.StatusType.SpecialBoss)
             {
                 var hp = ZUnit.HP;
                 var pg = (float)ZUnit.HP * 100 / ZUnit.MaxHP;
                 EventSystem.Instance.Publish<HPRefresh>(HPRefresh.Static.Clone(HPRefresh.Index.Boss, pg, hp));
-                Log.Debug($"Boss({ZUnit.ObjectID}) hp: {ZUnit.HP}/{ZUnit.MaxHP}");
+                //Log.Debug($"Boss({ZUnit.ObjectID}) hp: {ZUnit.HP}/{ZUnit.MaxHP}");
             }
         }
         //Log.Debug($"hp({ZUnit.ObjectID}) change: {ZUnit.HP}");