Selaa lähdekoodia

修改消息分发器支持泛型

大爷 2 vuotta sitten
vanhempi
commit
f9ab00fabd

+ 7 - 8
Unity/Assets/Scripts/Codes/Model/Share/EventDispatcher.cs

@@ -1,31 +1,30 @@
 using System;
 using System.Collections.Generic;
-using ObjectEventAction = System.Action<CommonAI.Zone.ObjectEvent>;
 
 namespace ET
 {
-    public class EventDispatcher
+    public class EventDispatcher<A>
     {
-        private Dictionary<Type, List<ObjectEventAction>> _list = new();
+        private Dictionary<Type, List<Action<A>>> _list = new();
         public EventDispatcher() { }
 
-        public ObjectEventAction AddListener<T>(ObjectEventAction action)
+        public Action<A> AddListener<T>(Action<A> action)
         {
-            List<ObjectEventAction> acts;
+            List<Action<A>> acts;
             if (_list.TryGetValue(typeof(T), out acts))
             {
                 acts.Add(action);
             }
             else
             {
-                _list.Add(typeof(T), new List<ObjectEventAction> { action });
+                _list.Add(typeof(T), new List<Action<A>> { action });
             }
             return action;
         }
 
-        public void Notfify(CommonAI.Zone.ObjectEvent ev)
+        public void Notfify(A ev)
         {
-            List<ObjectEventAction> acts;
+            List<Action<A>> acts;
             if (_list.TryGetValue(ev.GetType(), out acts))
             {
                 foreach (var act in acts)

+ 0 - 52
Unity/Assets/Scripts/Codes/Model/Share/EventDispatcherComponent.cs

@@ -1,52 +0,0 @@
-using System;
-using System.Collections.Generic;
-using ObjectEventAction = System.Action<CommonAI.Zone.ObjectEvent>;
-
-namespace ET
-{
-    
-    [FriendOf(typeof(EventDispatcherComponent))]
-    public static class EventDispatcherComponentSystem
-    {
-        [ObjectSystem]
-        public class EventDispatcherComponentAwakeSystem : AwakeSystem<EventDispatcherComponent>
-        {
-            protected override void Awake(EventDispatcherComponent self)
-            {
-                self.list.Clear();
-            }
-        }
-
-        public static ObjectEventAction AddListener<T>(this EventDispatcherComponent self, ObjectEventAction action)
-        {
-            List<ObjectEventAction> acts;
-            if(self.list.TryGetValue(typeof(T), out acts))
-            {
-                acts.Add(action);
-            }
-            else
-            {
-                self.list.Add(typeof(T), new List<ObjectEventAction> { action });
-            }
-            return action;
-        }
-
-        public static void Notfify(this EventDispatcherComponent self, CommonAI.Zone.ObjectEvent ev)
-        {
-            List<ObjectEventAction> acts;
-            if (self.list.TryGetValue(ev.GetType(), out acts))
-            {
-                foreach(var act in acts)
-                {
-                    act.Invoke(ev);
-                }
-            }
-        }
-    }
-
-    [ComponentOf]
-    public class EventDispatcherComponent : Entity, IAwake
-    {
-        public Dictionary<Type, List<ObjectEventAction>> list = new();
-    }
-}

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Share/EventDispatcherComponent.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 3194cd0e383dc3a44a454ed432cb8c6e
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: