提交 a808568b 编写于 作者: T tanghai

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

上级 89c73348
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))
{
......
......@@ -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" />
......
......@@ -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" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册