Просмотр исходного кода

事件管理器也做成World的一个Component

tanghai 11 лет назад
Родитель
Сommit
a808568bfb

+ 10 - 8
CSharp/Platform/Common/Event/EventTrigger.cs → CSharp/Game/Model/Component/EventComponent.cs

@@ -1,21 +1,23 @@
 using System;
 using System.Collections.Generic;
+using System.Reflection;
+using Common.Base;
+using Common.Event;
 
-namespace Common.Event
+namespace Model
 {
-    public class EventTrigger<T> where T : AEventAttribute
+    public class EventComponent<T>: Component<World> where T : AEventAttribute
     {
-        private readonly Dictionary<int, List<IEvent>> events;
+        private Dictionary<int, List<IEvent>> events;
 
-        public EventTrigger()
+        public void Load(Assembly assembly)
         {
             this.events = new Dictionary<int, List<IEvent>>();
 
-            Type type = typeof (T);
-            var types = type.Assembly.GetTypes();
+            var types = assembly.GetTypes();
             foreach (var t in types)
             {
-                object[] attrs = t.GetCustomAttributes(type, false);
+                object[] attrs = t.GetCustomAttributes(typeof (T), false);
                 if (attrs.Length == 0)
                 {
                     continue;
@@ -28,7 +30,7 @@ namespace Common.Event
                             obj.GetType().FullName));
                 }
 
-                AEventAttribute iEventAttribute = (T) attrs[0];
+                AEventAttribute iEventAttribute = (AEventAttribute) attrs[0];
 
                 if (!this.events.ContainsKey(iEventAttribute.Type))
                 {

+ 1 - 0
CSharp/Game/Model/Model.csproj

@@ -54,6 +54,7 @@
     <Compile Include="Buff.cs" />
     <Compile Include="Component\BuffComponent.cs" />
     <Compile Include="Component\ConfigComponent.cs" />
+    <Compile Include="Component\EventComponent.cs" />
     <Compile Include="Config\UnitConfig.cs" />
     <Compile Include="Config\BuffConfig.cs" />
     <Compile Include="FactoryAttribute.cs" />

+ 0 - 1
CSharp/Platform/Common/Common.csproj

@@ -62,7 +62,6 @@
     <Compile Include="Base\Component.cs" />
     <Compile Include="Base\MultiMap.cs" />
     <Compile Include="Config\ICategory.cs" />
-    <Compile Include="Event\EventTrigger.cs" />
     <Compile Include="Event\Env.cs" />
     <Compile Include="Event\AEventAttribute.cs" />
     <Compile Include="Event\IEvent.cs" />