提交 4d424dfa 编写于 作者: T tanghai

修复server编译的问题

上级 6787974e
using System;
using System.Collections.Generic;
namespace Model
{
[ObjectEvent]
public class EventComponentEvent : ObjectEvent<EventComponent>, IAwake, ILoad
{
public void Awake()
{
this.Get().Awake();
}
public void Load()
{
this.Get().Load();
}
}
public class EventComponent : Component
{
private Dictionary<EventIdType, List<object>> allEvents;
public void Awake()
{
this.Load();
}
public void Load()
{
this.allEvents = new Dictionary<EventIdType, List<object>>();
Type[] types = DllHelper.GetMonoTypes();
foreach (Type type in types)
{
object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
foreach (object attr in attrs)
{
EventAttribute aEventAttribute = (EventAttribute)attr;
object obj = Activator.CreateInstance(type);
if (!this.allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
{
this.allEvents.Add((EventIdType)aEventAttribute.Type, new List<object>());
}
this.allEvents[(EventIdType)aEventAttribute.Type].Add(obj);
}
}
}
public void Run(EventIdType type)
{
List<object> iEvents;
if (!this.allEvents.TryGetValue(type, out iEvents))
{
return;
}
foreach (object obj in iEvents)
{
try
{
IEvent iEvent = (IEvent)obj;
iEvent.Run();
}
catch (Exception e)
{
Log.Error(e.ToString());
}
}
}
public void Run<A>(EventIdType type, A a)
{
List<object> iEvents;
if (!this.allEvents.TryGetValue(type, out iEvents))
{
return;
}
foreach (object obj in iEvents)
{
try
{
IEvent<A> iEvent = (IEvent<A>)obj;
iEvent.Run(a);
}
catch (Exception err)
{
Log.Error(err.ToString());
}
}
}
public void Run<A, B>(EventIdType type, A a, B b)
{
List<object> iEvents;
if (!this.allEvents.TryGetValue(type, out iEvents))
{
return;
}
foreach (object obj in iEvents)
{
try
{
IEvent<A, B> iEvent = (IEvent<A, B>)obj;
iEvent.Run(a, b);
}
catch (Exception err)
{
Log.Error(err.ToString());
}
}
}
public void Run<A, B, C>(EventIdType type, A a, B b, C c)
{
List<object> iEvents;
if (!this.allEvents.TryGetValue(type, out iEvents))
{
return;
}
foreach (object obj in iEvents)
{
try
{
IEvent<A, B, C> iEvent = (IEvent<A, B, C>)obj;
iEvent.Run(a, b, c);
}
catch (Exception err)
{
Log.Error(err.ToString());
}
}
}
}
}
\ No newline at end of file
......@@ -39,7 +39,6 @@
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectEventAttribute.cs" Link="Base\Object\ObjectEventAttribute.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectPool.cs" Link="Base\Object\ObjectPool.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\ConfigComponent.cs" Link="Component\ConfigComponent.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\EventComponent.cs" Link="Component\EventComponent.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\NetworkComponent.cs" Link="Component\NetworkComponent.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\TimerComponent.cs" Link="Component\TimerComponent.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\Opcode.cs" Link="Entity\Message\Opcode.cs" />
......@@ -64,5 +63,4 @@
<ProjectReference Include="..\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Driver.Core\MongoDB.Driver.Core.csproj" />
<ProjectReference Include="..\ThirdParty\MongodbDriver\DotNetCoreDriver\MongoDB.Driver\MongoDB.Driver.csproj" />
</ItemGroup>
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册