Преглед изворни кода

1.默认Component不会序列化,只有继承ComponentDB的组件才会序列化
2.对象事件改回之前的方式

tanghai пре 8 година
родитељ
комит
a99a4896ce
39 измењених фајлова са 582 додато и 655 уклоњено
  1. 3 3
      Server/App/Program.cs
  2. 10 3
      Server/Hotfix/Component/RealmGateAddressComponentE.cs
  3. 1 1
      Server/Hotfix/Message/M2A_ReloadHandler.cs
  4. 10 2
      Server/Model/Component/AppManagerComponent.cs
  5. 16 12
      Server/Model/Component/ConfigComponent.cs
  6. 23 17
      Server/Model/Component/EventComponent.cs
  7. 10 2
      Server/Model/Component/GateSessionKeyComponent.cs
  8. 1 2
      Server/Model/Component/KVComponent.cs
  9. 20 11
      Server/Model/Component/MessageDispatherComponent.cs
  10. 23 6
      Server/Model/Component/NetInnerComponent.cs
  11. 22 4
      Server/Model/Component/NetOuterComponent.cs
  12. 2 4
      Server/Model/Component/NetworkComponent.cs
  13. 10 2
      Server/Model/Component/OptionComponent.cs
  14. 0 1
      Server/Model/Component/RealmGateAddressComponent.cs
  15. 0 1
      Server/Model/Component/RobotComponent.cs
  16. 10 3
      Server/Model/Component/StartConfigComponent.cs
  17. 11 5
      Server/Model/Component/TimerComponent.cs
  18. 9 1
      Server/Model/Component/Unit/LockComponent.cs
  19. 1 2
      Server/Model/Component/Unit/MasterComponent.cs
  20. 1 3
      Server/Model/Component/UnitComponent.cs
  21. 3 5
      Server/Model/Config/ACategory.cs
  22. 1 1
      Server/Model/Config/AConfigComponent.cs
  23. 7 77
      Server/Model/Entity/Game.cs
  24. 1 2
      Server/Model/Entity/Session.cs
  25. 1 1
      Server/Model/Helper/DllHelper.cs
  26. 5 5
      Server/Model/Object/Component.cs
  27. 9 0
      Server/Model/Object/ComponentDB.cs
  28. 0 4
      Server/Model/Object/Disposer.cs
  29. 33 21
      Server/Model/Object/Entity.cs
  30. 0 15
      Server/Model/Object/EntityEventAttribute.cs
  31. 0 411
      Server/Model/Object/EntityEventManager.cs
  32. 22 0
      Server/Model/Object/IAwake.cs
  33. 7 0
      Server/Model/Object/ILoad.cs
  34. 7 0
      Server/Model/Object/IUpdate.cs
  35. 9 0
      Server/Model/Object/ObjectEventAttribute.cs
  36. 262 0
      Server/Model/Object/ObjectEvents.cs
  37. 24 24
      Server/Model/Other/EntityEventId.cs
  38. 6 2
      Server/Model/Server.Model.csproj
  39. 2 2
      Server/Server.sln

+ 3 - 3
Server/App/Program.cs

@@ -15,8 +15,8 @@ namespace App
 
 
 			try
 			try
 			{
 			{
-				Game.EntityEventManager.Register("Model", typeof(Game).Assembly);
-				Game.EntityEventManager.Register("Hotfix", DllHelper.GetHotfixAssembly());
+				ObjectEvents.Instance.Register("Model", typeof(Game).Assembly);
+				ObjectEvents.Instance.Register("Hotfix", DllHelper.GetHotfixAssembly());
 
 
 				Options options = Game.Scene.AddComponent<OptionComponent, string[]>(args).Options;
 				Options options = Game.Scene.AddComponent<OptionComponent, string[]>(args).Options;
 				StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;
 				StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;
@@ -72,7 +72,7 @@ namespace App
 					{
 					{
 						Thread.Sleep(1);
 						Thread.Sleep(1);
 						Game.Poller.Update();
 						Game.Poller.Update();
-						Game.EntityEventManager.Update();
+						ObjectEvents.Instance.Update();
 					}
 					}
 					catch (Exception e)
 					catch (Exception e)
 					{
 					{

+ 10 - 3
Server/Hotfix/Component/RealmGateAddressComponentE.cs

@@ -1,9 +1,16 @@
-using Base;
-using Model;
+using Model;
 
 
 namespace Hotfix
 namespace Hotfix
 {
 {
-	[EntityEvent(EntityEventId.RealmGateAddressComponent)]
+	[ObjectEvent]
+	public class RealmGateAddressComponentEvent : ObjectEvent<RealmGateAddressComponent>, IAwake
+	{
+		public void Awake()
+		{
+			this.Get().Awake();
+		}
+	}
+	
 	public static class RealmGateAddressComponentE
 	public static class RealmGateAddressComponentE
 	{
 	{
 		public static void Awake(this RealmGateAddressComponent component)
 		public static void Awake(this RealmGateAddressComponent component)

+ 1 - 1
Server/Hotfix/Message/M2A_ReloadHandler.cs

@@ -12,7 +12,7 @@ namespace Hotfix
 			A2M_Reload response = new A2M_Reload();
 			A2M_Reload response = new A2M_Reload();
 			try
 			try
 			{
 			{
-				Game.EntityEventManager.Register("Controller", DllHelper.GetHotfixAssembly());
+				ObjectEvents.Instance.Register("Hotfix", DllHelper.GetHotfixAssembly());
 				reply(response);
 				reply(response);
 			}
 			}
 			catch (Exception e)
 			catch (Exception e)

+ 10 - 2
Server/Model/Component/AppManagerComponent.cs

@@ -6,12 +6,20 @@ using Base;
 
 
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.AppManagerComponent)]
+	[ObjectEvent]
+	public class AppManagerComponentEvent : ObjectEvent<AppManagerComponent>, IAwake
+	{
+		public void Awake()
+		{
+			this.Get().Awake();
+		}
+	}
+
 	public class AppManagerComponent: Component
 	public class AppManagerComponent: Component
 	{
 	{
 		private readonly Dictionary<int, Process> processes = new Dictionary<int, Process>();
 		private readonly Dictionary<int, Process> processes = new Dictionary<int, Process>();
 
 
-		private void Awake()
+		public void Awake()
 		{
 		{
 			string[] ips = NetHelper.GetAddressIPs();
 			string[] ips = NetHelper.GetAddressIPs();
 			StartConfig[] startConfigs = Game.Scene.GetComponent<StartConfigComponent>().GetAll();
 			StartConfig[] startConfigs = Game.Scene.GetComponent<StartConfigComponent>().GetAll();

+ 16 - 12
Server/Model/Component/ConfigComponent.cs

@@ -4,13 +4,22 @@ using System.Reflection;
 
 
 namespace Model
 namespace Model
 {
 {
+	[ObjectEvent]
+	public class ConfigComponentEvent : ObjectEvent<ConfigComponent>, ILoad
+	{
+		public void Load()
+		{
+			this.Get().Load();
+		}
+	}
+
 	public class ConfigComponent: Component
 	public class ConfigComponent: Component
 	{
 	{
 		private Dictionary<Type, ICategory> allConfig;
 		private Dictionary<Type, ICategory> allConfig;
 
 
-		private void Load()
+		public void Load()
 		{
 		{
-			Assembly assembly = Game.EntityEventManager.GetAssembly("Base");
+			Assembly assembly = ObjectEvents.Instance.GetAssembly("Model");
 
 
 			this.allConfig = new Dictionary<Type, ICategory>();
 			this.allConfig = new Dictionary<Type, ICategory>();
 			Type[] types = assembly.GetTypes();
 			Type[] types = assembly.GetTypes();
@@ -39,8 +48,7 @@ namespace Model
 		public T GetOne<T>() where T : AConfig
 		public T GetOne<T>() where T : AConfig
 		{
 		{
 			Type type = typeof (T);
 			Type type = typeof (T);
-			ICategory configCategory;
-			if (!this.allConfig.TryGetValue(type, out configCategory))
+			if (!this.allConfig.TryGetValue(type, out ICategory configCategory))
 			{
 			{
 				throw new Exception($"ConfigComponent not found key: {type.FullName}");
 				throw new Exception($"ConfigComponent not found key: {type.FullName}");
 			}
 			}
@@ -50,8 +58,7 @@ namespace Model
 		public T Get<T>(long id) where T : AConfig
 		public T Get<T>(long id) where T : AConfig
 		{
 		{
 			Type type = typeof (T);
 			Type type = typeof (T);
-			ICategory configCategory;
-			if (!this.allConfig.TryGetValue(type, out configCategory))
+			if (!this.allConfig.TryGetValue(type, out ICategory configCategory))
 			{
 			{
 				throw new Exception($"ConfigComponent not found key: {type.FullName}");
 				throw new Exception($"ConfigComponent not found key: {type.FullName}");
 			}
 			}
@@ -61,8 +68,7 @@ namespace Model
 		public T TryGet<T>(int id) where T : AConfig
 		public T TryGet<T>(int id) where T : AConfig
 		{
 		{
 			Type type = typeof (T);
 			Type type = typeof (T);
-			ICategory configCategory;
-			if (!this.allConfig.TryGetValue(type, out configCategory))
+			if (!this.allConfig.TryGetValue(type, out ICategory configCategory))
 			{
 			{
 				return default(T);
 				return default(T);
 			}
 			}
@@ -72,8 +78,7 @@ namespace Model
 		public T[] GetAll<T>() where T : AConfig
 		public T[] GetAll<T>() where T : AConfig
 		{
 		{
 			Type type = typeof (T);
 			Type type = typeof (T);
-			ICategory configCategory;
-			if (!this.allConfig.TryGetValue(type, out configCategory))
+			if (!this.allConfig.TryGetValue(type, out ICategory configCategory))
 			{
 			{
 				throw new Exception($"ConfigComponent not found key: {type.FullName}");
 				throw new Exception($"ConfigComponent not found key: {type.FullName}");
 			}
 			}
@@ -84,8 +89,7 @@ namespace Model
 		{
 		{
 			T t = new T();
 			T t = new T();
 			Type type = t.ConfigType;
 			Type type = t.ConfigType;
-			ICategory category;
-			bool ret = this.allConfig.TryGetValue(type, out category);
+			bool ret = this.allConfig.TryGetValue(type, out ICategory category);
 			return ret? (T) category : null;
 			return ret? (T) category : null;
 		}
 		}
 	}
 	}

+ 23 - 17
Server/Model/Component/EventComponent.cs

@@ -4,20 +4,33 @@ using Base;
 
 
 namespace Model
 namespace Model
 {
 {
+	[ObjectEvent]
+	public class EventComponentEvent : ObjectEvent<EventComponent>, IAwake, ILoad
+	{
+		public void Awake()
+		{
+			this.Get().Awake();
+		}
+
+		public void Load()
+		{
+			this.Get().Load();
+		}
+	}
+
 	/// <summary>
 	/// <summary>
 	/// 事件分发
 	/// 事件分发
 	/// </summary>
 	/// </summary>
-	[EntityEvent(EntityEventId.EventComponent)]
 	public class EventComponent: Component
 	public class EventComponent: Component
 	{
 	{
 		private Dictionary<int, List<object>> allEvents;
 		private Dictionary<int, List<object>> allEvents;
 
 
-		private void Awake()
+		public void Awake()
 		{
 		{
 			this.Load();
 			this.Load();
 		}
 		}
 
 
-		private void Load()
+		public void Load()
 		{
 		{
 			this.allEvents = new Dictionary<int, List<object>>();
 			this.allEvents = new Dictionary<int, List<object>>();
 
 
@@ -42,8 +55,7 @@ namespace Model
 
 
 		public void Run(int type)
 		public void Run(int type)
 		{
 		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
+			if (!this.allEvents.TryGetValue(type, out List<object> iEvents))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -68,8 +80,7 @@ namespace Model
 
 
 		public void Run<A>(int type, A a)
 		public void Run<A>(int type, A a)
 		{
 		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
+			if (!this.allEvents.TryGetValue(type, out List<object> iEvents))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -94,8 +105,7 @@ namespace Model
 
 
 		public void Run<A, B>(int type, A a, B b)
 		public void Run<A, B>(int type, A a, B b)
 		{
 		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
+			if (!this.allEvents.TryGetValue(type, out List<object> iEvents))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -120,8 +130,7 @@ namespace Model
 
 
 		public void Run<A, B, C>(int type, A a, B b, C c)
 		public void Run<A, B, C>(int type, A a, B b, C c)
 		{
 		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
+			if (!this.allEvents.TryGetValue(type, out List<object> iEvents))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -146,8 +155,7 @@ namespace Model
 
 
 		public void Run<A, B, C, D>(int type, A a, B b, C c, D d)
 		public void Run<A, B, C, D>(int type, A a, B b, C c, D d)
 		{
 		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
+			if (!this.allEvents.TryGetValue(type, out List<object> iEvents))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -172,8 +180,7 @@ namespace Model
 
 
 		public void Run<A, B, C, D, E>(int type, A a, B b, C c, D d, E e)
 		public void Run<A, B, C, D, E>(int type, A a, B b, C c, D d, E e)
 		{
 		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
+			if (!this.allEvents.TryGetValue(type, out List<object> iEvents))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -199,8 +206,7 @@ namespace Model
 
 
 		public void Run<A, B, C, D, E, F>(int type, A a, B b, C c, D d, E e, F f)
 		public void Run<A, B, C, D, E, F>(int type, A a, B b, C c, D d, E e, F f)
 		{
 		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
+			if (!this.allEvents.TryGetValue(type, out List<object> iEvents))
 			{
 			{
 				return;
 				return;
 			}
 			}

+ 10 - 2
Server/Model/Component/GateSessionKeyComponent.cs

@@ -3,14 +3,22 @@ using Base;
 
 
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.GateSessionKeyComponent)]
+	[ObjectEvent]
+	public class GateSessionKeyComponentEvent : ObjectEvent<GateSessionKeyComponent>, IAwake
+	{
+		public void Awake()
+		{
+			this.Get().Awake();
+		}
+	}
+	
 	public class GateSessionKeyComponent : Component
 	public class GateSessionKeyComponent : Component
 	{
 	{
 		private TimerComponent timerComponent;
 		private TimerComponent timerComponent;
 
 
 		private readonly HashSet<long> sessionKey = new HashSet<long>();
 		private readonly HashSet<long> sessionKey = new HashSet<long>();
 
 
-		private void Awake()
+		public void Awake()
 		{
 		{
 			this.timerComponent = Game.Scene.GetComponent<TimerComponent>();
 			this.timerComponent = Game.Scene.GetComponent<TimerComponent>();
 		}
 		}

+ 1 - 2
Server/Model/Component/KVComponent.cs

@@ -23,8 +23,7 @@ namespace Model
 
 
 		public T Get<T>(string key)
 		public T Get<T>(string key)
 		{
 		{
-			object k;
-			if (!this.kv.TryGetValue(key, out k))
+			if (!this.kv.TryGetValue(key, out object k))
 			{
 			{
 				return default(T);
 				return default(T);
 			}
 			}

+ 20 - 11
Server/Model/Component/MessageDispatherComponent.cs

@@ -4,10 +4,23 @@ using Base;
 
 
 namespace Model
 namespace Model
 {
 {
+	[ObjectEvent]
+	public class MessageDispatherComponentEvent : ObjectEvent<MessageDispatherComponent>, IAwake<AppType>, ILoad
+	{
+		public void Awake(AppType appType)
+		{
+			this.Get().Awake(appType);
+		}
+
+		public void Load()
+		{
+			this.Get().Load();
+		}
+	}
+
 	/// <summary>
 	/// <summary>
 	/// 消息分发组件
 	/// 消息分发组件
 	/// </summary>
 	/// </summary>
-	[EntityEvent(EntityEventId.MessageDispatherComponent)]
 	public class MessageDispatherComponent : Component
 	public class MessageDispatherComponent : Component
 	{
 	{
 		private AppType AppType;
 		private AppType AppType;
@@ -15,13 +28,13 @@ namespace Model
 		private Dictionary<Type, MessageAttribute> messageOpcode { get; set; }
 		private Dictionary<Type, MessageAttribute> messageOpcode { get; set; }
 		private Dictionary<ushort, Type> opcodeType { get; set; }
 		private Dictionary<ushort, Type> opcodeType { get; set; }
 
 
-		private void Awake(AppType appType)
+		public void Awake(AppType appType)
 		{
 		{
 			this.AppType = appType;
 			this.AppType = appType;
 			this.Load();
 			this.Load();
 		}
 		}
 
 
-		private void Load()
+		public void Load()
 		{
 		{
 			this.handlers = new Dictionary<ushort, List<IMHandler>>();
 			this.handlers = new Dictionary<ushort, List<IMHandler>>();
 			this.messageOpcode = new Dictionary<Type, MessageAttribute>();
 			this.messageOpcode = new Dictionary<Type, MessageAttribute>();
@@ -65,8 +78,7 @@ namespace Model
 
 
 				Type messageType = imHandler.GetMessageType();
 				Type messageType = imHandler.GetMessageType();
 				ushort opcode = this.GetOpcode(messageType);
 				ushort opcode = this.GetOpcode(messageType);
-				List<IMHandler> list;
-				if (!this.handlers.TryGetValue(opcode, out list))
+				if (!this.handlers.TryGetValue(opcode, out List<IMHandler> list))
 				{
 				{
 					list = new List<IMHandler>();
 					list = new List<IMHandler>();
 					this.handlers.Add(opcode, list);
 					this.handlers.Add(opcode, list);
@@ -77,8 +89,7 @@ namespace Model
 
 
 		public ushort GetOpcode(Type type)
 		public ushort GetOpcode(Type type)
 		{
 		{
-			MessageAttribute messageAttribute;
-			if (!this.messageOpcode.TryGetValue(type, out messageAttribute))
+			if (!this.messageOpcode.TryGetValue(type, out MessageAttribute messageAttribute))
 			{
 			{
 				throw new Exception($"查找Opcode失败: {type.Name}");
 				throw new Exception($"查找Opcode失败: {type.Name}");
 			}
 			}
@@ -87,8 +98,7 @@ namespace Model
 
 
 		public Type GetType(ushort opcode)
 		public Type GetType(ushort opcode)
 		{
 		{
-			Type messageType;
-			if (!this.opcodeType.TryGetValue(opcode, out messageType))
+			if (!this.opcodeType.TryGetValue(opcode, out Type messageType))
 			{
 			{
 				throw new Exception($"查找Opcode Type失败: {opcode}");
 				throw new Exception($"查找Opcode Type失败: {opcode}");
 			}
 			}
@@ -97,8 +107,7 @@ namespace Model
 
 
 		public void Handle(Session session, MessageInfo messageInfo)
 		public void Handle(Session session, MessageInfo messageInfo)
 		{
 		{
-			List<IMHandler> actions;
-			if (!this.handlers.TryGetValue(messageInfo.Opcode, out actions))
+			if (!this.handlers.TryGetValue(messageInfo.Opcode, out List<IMHandler> actions))
 			{
 			{
 				Log.Error($"消息 {messageInfo.Opcode} 没有处理");
 				Log.Error($"消息 {messageInfo.Opcode} 没有处理");
 				return;
 				return;

+ 23 - 6
Server/Model/Component/NetInnerComponent.cs

@@ -3,22 +3,40 @@ using Base;
 
 
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.NetInnerComponent)]
+	[ObjectEvent]
+	public class NetInnerComponentEvent : ObjectEvent<NetInnerComponent>, IAwake, IAwake<string, int>, IUpdate
+	{
+		public void Awake()
+		{
+			this.Get().Awake();
+		}
+
+		public void Awake(string a, int b)
+		{
+			this.Get().Awake(a, b);
+		}
+
+		public void Update()
+		{
+			this.Get().Update();
+		}
+	}
+	
 	public class NetInnerComponent: NetworkComponent
 	public class NetInnerComponent: NetworkComponent
 	{
 	{
 		private readonly Dictionary<string, Session> adressSessions = new Dictionary<string, Session>();
 		private readonly Dictionary<string, Session> adressSessions = new Dictionary<string, Session>();
 
 
-		private void Awake()
+		public void Awake()
 		{
 		{
 			this.Awake(NetworkProtocol.TCP);
 			this.Awake(NetworkProtocol.TCP);
 		}
 		}
 
 
-		private void Awake(string host, int port)
+		public void Awake(string host, int port)
 		{
 		{
 			this.Awake(NetworkProtocol.TCP, host, port);
 			this.Awake(NetworkProtocol.TCP, host, port);
 		}
 		}
 
 
-		private new void Update()
+		public new void Update()
 		{
 		{
 			base.Update();
 			base.Update();
 		}
 		}
@@ -40,8 +58,7 @@ namespace Model
 		/// </summary>
 		/// </summary>
 		public Session Get(string address)
 		public Session Get(string address)
 		{
 		{
-			Session session;
-			if (this.adressSessions.TryGetValue(address, out session))
+			if (this.adressSessions.TryGetValue(address, out Session session))
 			{
 			{
 				return session;
 				return session;
 			}
 			}

+ 22 - 4
Server/Model/Component/NetOuterComponent.cs

@@ -2,20 +2,38 @@
 
 
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.NetOuterComponent)]
+	[ObjectEvent]
+	public class NetOuterComponentEvent : ObjectEvent<NetOuterComponent>, IAwake, IAwake<string, int>, IUpdate
+	{
+		public void Awake()
+		{
+			this.Get().Awake();
+		}
+
+		public void Awake(string a, int b)
+		{
+			this.Get().Awake(a, b);
+		}
+
+		public void Update()
+		{
+			this.Get().Update();
+		}
+	}
+	
 	public class NetOuterComponent: NetworkComponent
 	public class NetOuterComponent: NetworkComponent
 	{
 	{
-		private void Awake()
+		public void Awake()
 		{
 		{
 			this.Awake(NetworkProtocol.UDP);
 			this.Awake(NetworkProtocol.UDP);
 		}
 		}
 
 
-		private void Awake(string host, int port)
+		public void Awake(string host, int port)
 		{
 		{
 			this.Awake(NetworkProtocol.UDP, host, port);
 			this.Awake(NetworkProtocol.UDP, host, port);
 		}
 		}
 
 
-		private new void Update()
+		public new void Update()
 		{
 		{
 			base.Update();
 			base.Update();
 		}
 		}

+ 2 - 4
Server/Model/Component/NetworkComponent.cs

@@ -68,8 +68,7 @@ namespace Model
 
 
 		public virtual void Remove(long id)
 		public virtual void Remove(long id)
 		{
 		{
-			Session session;
-			if (!this.sessions.TryGetValue(id, out session))
+			if (!this.sessions.TryGetValue(id, out Session session))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -79,8 +78,7 @@ namespace Model
 
 
 		public Session Get(long id)
 		public Session Get(long id)
 		{
 		{
-			Session session;
-			this.sessions.TryGetValue(id, out session);
+			this.sessions.TryGetValue(id, out Session session);
 			return session;
 			return session;
 		}
 		}
 
 

+ 10 - 2
Server/Model/Component/OptionComponent.cs

@@ -3,12 +3,20 @@ using CommandLine;
 
 
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.OptionComponent)]
+	[ObjectEvent]
+	public class OptionComponentEvent : ObjectEvent<OptionComponent>, IAwake<string[]>
+	{
+		public void Awake(string[] args)
+		{
+			this.Get().Awake(args);
+		}
+	}
+	
 	public class OptionComponent : Component
 	public class OptionComponent : Component
 	{
 	{
 		public Options Options { get; } = new Options();
 		public Options Options { get; } = new Options();
 
 
-		private void Awake(string[] args)
+		public void Awake(string[] args)
 		{
 		{
 			if (!Parser.Default.ParseArguments(args, this.Options))
 			if (!Parser.Default.ParseArguments(args, this.Options))
 			{
 			{

+ 0 - 1
Server/Model/Component/RealmGateAddressComponent.cs

@@ -3,7 +3,6 @@ using Base;
 
 
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.RealmGateAddressComponent)]
 	public class RealmGateAddressComponent : Component
 	public class RealmGateAddressComponent : Component
 	{
 	{
 		public readonly List<StartConfig> GateAddress = new List<StartConfig>();
 		public readonly List<StartConfig> GateAddress = new List<StartConfig>();

+ 0 - 1
Server/Model/Component/RobotComponent.cs

@@ -1,6 +1,5 @@
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.RobotComponent)]
 	public class RobotComponent: Component
 	public class RobotComponent: Component
 	{
 	{
 		public override void Dispose()
 		public override void Dispose()

+ 10 - 3
Server/Model/Component/StartConfigComponent.cs

@@ -2,11 +2,18 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.IO;
 using System.IO;
 using Base;
 using Base;
-using MongoDB.Bson;
 
 
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.StartConfigComponent)]
+	[ObjectEvent]
+	public class StartConfigComponentEvent : ObjectEvent<StartConfigComponent>, IAwake<string, int>
+	{
+		public void Awake(string a, int b)
+		{
+			this.Get().Awake(a, b);
+		}
+	}
+	
 	public class StartConfigComponent: Component
 	public class StartConfigComponent: Component
 	{
 	{
 		private readonly List<StartConfig> allConfigs = new List<StartConfig>();
 		private readonly List<StartConfig> allConfigs = new List<StartConfig>();
@@ -15,7 +22,7 @@ namespace Model
 		
 		
 		public StartConfig StartConfig { get; private set; }
 		public StartConfig StartConfig { get; private set; }
 
 
-		private void Awake(string path, int appId)
+		public void Awake(string path, int appId)
 		{
 		{
 			string[] ss = File.ReadAllText(path).Split('\n');
 			string[] ss = File.ReadAllText(path).Split('\n');
 			foreach (string s in ss)
 			foreach (string s in ss)

+ 11 - 5
Server/Model/Component/TimerComponent.cs

@@ -5,6 +5,15 @@ using Base;
 
 
 namespace Model
 namespace Model
 {
 {
+	[ObjectEvent]
+	public class TimerComponentEvent: ObjectEvent<TimerComponent>, IUpdate
+	{
+		public void Update()
+		{
+			this.Get().Update();
+		}
+	}
+
 	public class Timer
 	public class Timer
 	{
 	{
 		public long Id { get; set; }
 		public long Id { get; set; }
@@ -12,7 +21,6 @@ namespace Model
 		public TaskCompletionSource<bool> tcs;
 		public TaskCompletionSource<bool> tcs;
 	}
 	}
 
 
-	[EntityEvent(EntityEventId.TimerComponent)]
 	public class TimerComponent: Component
 	public class TimerComponent: Component
 	{
 	{
 		private readonly Dictionary<long, Timer> timers = new Dictionary<long, Timer>();
 		private readonly Dictionary<long, Timer> timers = new Dictionary<long, Timer>();
@@ -42,8 +50,7 @@ namespace Model
 				long[] timeOutId = this.timeId.GetAll(key);
 				long[] timeOutId = this.timeId.GetAll(key);
 				foreach (long id in timeOutId)
 				foreach (long id in timeOutId)
 				{
 				{
-					Timer timer;
-					if (!this.timers.TryGetValue(id, out timer))
+					if (!this.timers.TryGetValue(id, out Timer timer))
 					{
 					{
 						continue;
 						continue;
 					}
 					}
@@ -55,8 +62,7 @@ namespace Model
 
 
 		private void Remove(long id)
 		private void Remove(long id)
 		{
 		{
-			Timer timer;
-			if (!this.timers.TryGetValue(id, out timer))
+			if (!this.timers.TryGetValue(id, out Timer timer))
 			{
 			{
 				return;
 				return;
 			}
 			}

+ 9 - 1
Server/Model/Component/Unit/LockComponent.cs

@@ -12,10 +12,18 @@ namespace Model
 		Locked,
 		Locked,
 	}
 	}
 
 
+	[ObjectEvent]
+	public class LockComponentEvent : ObjectEvent<LockComponent>, IAwake<string>
+	{
+		public void Awake(string a)
+		{
+			this.Get().Awake(a);
+		}
+	}
+
 	/// <summary>
 	/// <summary>
 	/// 分布式锁组件,Unit对象可能在不同进程上有镜像,访问该对象的时候需要对他加锁
 	/// 分布式锁组件,Unit对象可能在不同进程上有镜像,访问该对象的时候需要对他加锁
 	/// </summary>
 	/// </summary>
-	[EntityEvent(EntityEventId.LockComponent)]
 	public class LockComponent: Component
 	public class LockComponent: Component
 	{
 	{
 		private LockStatus status = LockStatus.LockedNot;
 		private LockStatus status = LockStatus.LockedNot;

+ 1 - 2
Server/Model/Component/Unit/MasterComponent.cs

@@ -15,8 +15,7 @@ namespace Model
 			this.Tcs = tcs;
 			this.Tcs = tcs;
 		}
 		}
 	}
 	}
-
-	[EntityEvent(EntityEventId.MasterComponent)]
+	
 	public class MasterComponent : Component
 	public class MasterComponent : Component
 	{
 	{
 		/// 镜像的地址
 		/// 镜像的地址

+ 1 - 3
Server/Model/Component/UnitComponent.cs

@@ -2,7 +2,6 @@
 
 
 namespace Model
 namespace Model
 {
 {
-	[EntityEvent(EntityEventId.UnitComponent)]
 	public class UnitComponent: Component
 	public class UnitComponent: Component
 	{
 	{
 		private readonly Dictionary<long, Unit> idUnits = new Dictionary<long, Unit>();
 		private readonly Dictionary<long, Unit> idUnits = new Dictionary<long, Unit>();
@@ -14,8 +13,7 @@ namespace Model
 
 
 		public Unit Get(long id)
 		public Unit Get(long id)
 		{
 		{
-			Unit unit;
-			this.idUnits.TryGetValue(id, out unit);
+			this.idUnits.TryGetValue(id, out Unit unit);
 			return unit;
 			return unit;
 		}
 		}
 
 

+ 3 - 5
Server/Model/Config/ACategory.cs

@@ -54,10 +54,9 @@ namespace Model
 		{
 		{
 			get
 			get
 			{
 			{
-				T t;
-				if (!this.dict.TryGetValue(type, out t))
+				if (!this.dict.TryGetValue(type, out T t))
 				{
 				{
-					throw new KeyNotFoundException($"{typeof (T)} 没有找到配置, key: {type}");
+					throw new KeyNotFoundException($"{typeof(T)} 没有找到配置, key: {type}");
 				}
 				}
 				return t;
 				return t;
 			}
 			}
@@ -65,8 +64,7 @@ namespace Model
 
 
 		public T TryGet(int type)
 		public T TryGet(int type)
 		{
 		{
-			T t;
-			if (!this.dict.TryGetValue(type, out t))
+			if (!this.dict.TryGetValue(type, out T t))
 			{
 			{
 				return null;
 				return null;
 			}
 			}

+ 1 - 1
Server/Model/Config/AConfigComponent.cs

@@ -8,7 +8,7 @@ namespace Model
 	[BsonKnownTypes(typeof (ClientConfig))]
 	[BsonKnownTypes(typeof (ClientConfig))]
 	[BsonKnownTypes(typeof (InnerConfig))]
 	[BsonKnownTypes(typeof (InnerConfig))]
 	[BsonKnownTypes(typeof (OuterConfig))]
 	[BsonKnownTypes(typeof (OuterConfig))]
-	public abstract class AConfigComponent: Component
+	public abstract class AConfigComponent: ComponentDB
 	{
 	{
 	}
 	}
 }
 }

+ 7 - 77
Server/Model/Entity/Game.cs

@@ -7,10 +7,6 @@ namespace Model
 {
 {
 	public static class Game
 	public static class Game
 	{
 	{
-		private static HashSet<Disposer> disposers;
-
-		private static EntityEventManager entityEventManager;
-
 		public static TPoller Poller { get; } = new TPoller();
 		public static TPoller Poller { get; } = new TPoller();
 
 
 		private static Scene scene;
 		private static Scene scene;
@@ -19,87 +15,21 @@ namespace Model
 		{
 		{
 			get
 			get
 			{
 			{
-				if (scene == null)
+				if (scene != null)
 				{
 				{
-					scene = new Scene();
-#if SERVER
-					scene.AddComponent<EventComponent>();
-#else
-					scene.AddComponent<EventComponent>();
-#endif
-					scene.AddComponent<TimerComponent>();
+					return scene;
 				}
 				}
+				scene = new Scene();
+				scene.AddComponent<EventComponent>();
+				scene.AddComponent<TimerComponent>();
 				return scene;
 				return scene;
 			}
 			}
 		}
 		}
-
-		public static HashSet<Disposer> Disposers
-		{
-			get
-			{
-				if (disposers == null)
-				{
-					disposers = new HashSet<Disposer>();
-				}
-				return disposers;
-			}
-		}
-
-		public static void CloseScene()
+		
+		public static void Close()
 		{
 		{
 			scene.Dispose();
 			scene.Dispose();
 			scene = null;
 			scene = null;
 		}
 		}
-
-		public static void ClearDisposers()
-		{
-			foreach (Disposer disposer in Disposers)
-			{
-				disposer.Dispose();
-			}
-			disposers.Clear();
-			disposers = null;
-		}
-
-		public static EntityEventManager EntityEventManager
-		{
-			get
-			{
-				if (entityEventManager == null)
-				{
-					entityEventManager = new EntityEventManager();
-				}
-				return entityEventManager;
-			}
-			set
-			{
-				entityEventManager = value;
-			}
-		}
-
-		public static string DisposerInfo()
-		{
-			var info = new Dictionary<string, int>();
-			foreach (Disposer disposer in Disposers)
-			{
-				if (info.ContainsKey(disposer.GetType().Name))
-				{
-					info[disposer.GetType().Name] += 1;
-				}
-				else
-				{
-					info[disposer.GetType().Name] = 1;
-				}
-			}
-			info = info.OrderByDescending(s => s.Value).ToDictionary(p => p.Key, p => p.Value);
-			StringBuilder sb = new StringBuilder();
-			sb.Append("\r\n");
-			foreach (string key in info.Keys)
-			{
-				sb.Append($"{info[key],10} {key}\r\n");
-			}
-
-			return sb.ToString();
-		}
 	}
 	}
 }
 }

+ 1 - 2
Server/Model/Entity/Session.cs

@@ -113,9 +113,8 @@ namespace Model
 			}
 			}
 
 
 			// rpcFlag>0 表示这是一个rpc响应消息
 			// rpcFlag>0 表示这是一个rpc响应消息
-			Action<byte[], int, int> action;
 			// Rpc回调有找不着的可能,因为client可能取消Rpc调用
 			// Rpc回调有找不着的可能,因为client可能取消Rpc调用
-			if (!this.requestCallback.TryGetValue(rpcId, out action))
+			if (!this.requestCallback.TryGetValue(rpcId, out Action<byte[], int, int> action))
 			{
 			{
 				return;
 				return;
 			}
 			}

+ 1 - 1
Server/Model/Helper/DllHelper.cs

@@ -22,7 +22,7 @@ namespace Model
 		public static Type[] GetMonoTypes()
 		public static Type[] GetMonoTypes()
 		{
 		{
 			List<Type> types = new List<Type>();
 			List<Type> types = new List<Type>();
-			foreach (Assembly assembly in Game.EntityEventManager.GetAssemblies())
+			foreach (Assembly assembly in ObjectEvents.Instance.GetAssemblies())
 			{
 			{
 				types.AddRange(assembly.GetTypes());
 				types.AddRange(assembly.GetTypes());
 			}
 			}

+ 5 - 5
Server/Model/Object/Component.cs

@@ -2,7 +2,7 @@
 
 
 namespace Model
 namespace Model
 {
 {
-	[BsonKnownTypes(typeof (AConfigComponent))]
+	[BsonKnownTypes(typeof(ComponentDB))]
 	public abstract class Component: Disposer
 	public abstract class Component: Disposer
 	{
 	{
 		[BsonIgnore]
 		[BsonIgnore]
@@ -15,12 +15,12 @@ namespace Model
 
 
 		protected Component()
 		protected Component()
 		{
 		{
-			Game.EntityEventManager.Add(this);
+			ObjectEvents.Instance.Add(this);
 		}
 		}
 
 
 		protected Component(long id): base(id)
 		protected Component(long id): base(id)
 		{
 		{
-			Game.EntityEventManager.Add(this);
+			ObjectEvents.Instance.Add(this);
 		}
 		}
 
 
 		public T GetComponent<T>() where T : Component
 		public T GetComponent<T>() where T : Component
@@ -39,14 +39,14 @@ namespace Model
 
 
 			this.Owner.RemoveComponent(this.GetType());
 			this.Owner.RemoveComponent(this.GetType());
 
 
-			Game.EntityEventManager.Remove(this);
+			ObjectEvents.Instance.Remove(this);
 		}
 		}
 
 
 		public override void EndInit()
 		public override void EndInit()
 		{
 		{
 			base.EndInit();
 			base.EndInit();
 
 
-			Game.EntityEventManager.Add(this);
+			ObjectEvents.Instance.Add(this);
 		}
 		}
 	}
 	}
 }
 }

+ 9 - 0
Server/Model/Object/ComponentDB.cs

@@ -0,0 +1,9 @@
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace Model
+{
+	[BsonKnownTypes(typeof(AConfigComponent))]
+	public abstract class ComponentDB : Component
+	{
+	}
+}

+ 0 - 4
Server/Model/Object/Disposer.cs

@@ -7,18 +7,15 @@ namespace Model
 	{
 	{
 		protected Disposer(): base(IdGenerater.GenerateId())
 		protected Disposer(): base(IdGenerater.GenerateId())
 		{
 		{
-			Game.Disposers.Add(this);
 		}
 		}
 
 
 		protected Disposer(long id): base(id)
 		protected Disposer(long id): base(id)
 		{
 		{
-			Game.Disposers.Add(this);
 		}
 		}
 
 
 		public virtual void Dispose()
 		public virtual void Dispose()
 		{
 		{
 			this.Id = 0;
 			this.Id = 0;
-			Game.Disposers.Remove(this);
 		}
 		}
 
 
 		public override void BeginInit()
 		public override void BeginInit()
@@ -27,7 +24,6 @@ namespace Model
 
 
 		public override void EndInit()
 		public override void EndInit()
 		{
 		{
-			Game.Disposers.Add(this);
 		}
 		}
 	}
 	}
 }
 }

+ 33 - 21
Server/Model/Object/Entity.cs

@@ -20,19 +20,19 @@ namespace Model
 		protected Entity()
 		protected Entity()
 		{
 		{
 			this.Type = EntityType.None;
 			this.Type = EntityType.None;
-			Game.EntityEventManager.Add(this);
+			ObjectEvents.Instance.Add(this);
 		}
 		}
 
 
 		protected Entity(EntityType entityType)
 		protected Entity(EntityType entityType)
 		{
 		{
 			this.Type = entityType;
 			this.Type = entityType;
-			Game.EntityEventManager.Add(this);
+			ObjectEvents.Instance.Add(this);
 		}
 		}
 
 
 		protected Entity(long id, EntityType entityType): base(id)
 		protected Entity(long id, EntityType entityType): base(id)
 		{
 		{
 			this.Type = entityType;
 			this.Type = entityType;
-			Game.EntityEventManager.Add(this);
+			ObjectEvents.Instance.Add(this);
 		}
 		}
 
 
 		public override void Dispose()
 		public override void Dispose()
@@ -56,7 +56,7 @@ namespace Model
 				}
 				}
 			}
 			}
 
 
-			Game.EntityEventManager.Remove(this);
+			ObjectEvents.Instance.Remove(this);
 		}
 		}
 
 
 		public K AddComponent<K>() where K : Component, new()
 		public K AddComponent<K>() where K : Component, new()
@@ -74,9 +74,12 @@ namespace Model
 				this.components = new HashSet<Component>();
 				this.components = new HashSet<Component>();
 			}
 			}
 
 
-			this.components.Add(component);
+			if (component is ComponentDB)
+			{
+				this.components.Add(component);
+			}
 			this.componentDict.Add(component.GetType(), component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.EntityEventManager.Awake(component);
+			ObjectEvents.Instance.Awake(component);
 			return component;
 			return component;
 		}
 		}
 
 
@@ -95,9 +98,12 @@ namespace Model
 				this.components = new HashSet<Component>();
 				this.components = new HashSet<Component>();
 			}
 			}
 
 
-			this.components.Add(component);
+			if (component is ComponentDB)
+			{
+				this.components.Add(component);
+			}
 			this.componentDict.Add(component.GetType(), component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.EntityEventManager.Awake(component, p1);
+			ObjectEvents.Instance.Awake(component, p1);
 			return component;
 			return component;
 		}
 		}
 
 
@@ -116,9 +122,12 @@ namespace Model
 				this.components = new HashSet<Component>();
 				this.components = new HashSet<Component>();
 			}
 			}
 
 
-			this.components.Add(component);
+			if (component is ComponentDB)
+			{
+				this.components.Add(component);
+			}
 			this.componentDict.Add(component.GetType(), component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.EntityEventManager.Awake(component, p1, p2);
+			ObjectEvents.Instance.Awake(component, p1, p2);
 			return component;
 			return component;
 		}
 		}
 
 
@@ -137,9 +146,12 @@ namespace Model
 				this.components = new HashSet<Component>();
 				this.components = new HashSet<Component>();
 			}
 			}
 
 
-			this.components.Add(component);
+			if (component is ComponentDB)
+			{
+				this.components.Add(component);
+			}
 			this.componentDict.Add(component.GetType(), component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.EntityEventManager.Awake(component, p1, p2, p3);
+			ObjectEvents.Instance.Awake(component, p1, p2, p3);
 			return component;
 			return component;
 		}
 		}
 
 
@@ -154,15 +166,17 @@ namespace Model
 			{
 			{
 				this.components = new HashSet<Component>();
 				this.components = new HashSet<Component>();
 			}
 			}
-			this.components.Add(component);
+			if (component is ComponentDB)
+			{
+				this.components.Add(component);
+			}
 			this.componentDict.Add(component.GetType(), component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.EntityEventManager.Awake(component);
+			ObjectEvents.Instance.Awake(component);
 		}
 		}
 
 
 		public void RemoveComponent<K>() where K : Component
 		public void RemoveComponent<K>() where K : Component
 		{
 		{
-			Component component;
-			if (!this.componentDict.TryGetValue(typeof (K), out component))
+			if (!this.componentDict.TryGetValue(typeof(K), out Component component))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -178,8 +192,7 @@ namespace Model
 
 
 		public void RemoveComponent(Type type)
 		public void RemoveComponent(Type type)
 		{
 		{
-			Component component;
-			if (!this.componentDict.TryGetValue(type, out component))
+			if (!this.componentDict.TryGetValue(type, out Component component))
 			{
 			{
 				return;
 				return;
 			}
 			}
@@ -195,8 +208,7 @@ namespace Model
 
 
 		public K GetComponent<K>() where K : Component
 		public K GetComponent<K>() where K : Component
 		{
 		{
-			Component component;
-			if (!this.componentDict.TryGetValue(typeof (K), out component))
+			if (!this.componentDict.TryGetValue(typeof(K), out Component component))
 			{
 			{
 				return default(K);
 				return default(K);
 			}
 			}
@@ -219,7 +231,7 @@ namespace Model
 		{
 		{
 			base.EndInit();
 			base.EndInit();
 
 
-			Game.EntityEventManager.Add(this);
+			ObjectEvents.Instance.Add(this);
 
 
 			if (this.components.Count == 0)
 			if (this.components.Count == 0)
 			{
 			{

+ 0 - 15
Server/Model/Object/EntityEventAttribute.cs

@@ -1,15 +0,0 @@
-using System;
-
-namespace Model
-{
-	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-	public class EntityEventAttribute: Attribute
-	{
-		public int ClassType;
-
-		public EntityEventAttribute(int classType)
-		{
-			this.ClassType = classType;
-		}
-	}
-}

+ 0 - 411
Server/Model/Object/EntityEventManager.cs

@@ -1,411 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using Base;
-
-#if !SERVER
-using ILRuntime.CLR.Method;
-using ILRuntime.CLR.TypeSystem;
-using ILRuntime.Runtime.Enviorment;
-using UnityEngine;
-#endif
-
-namespace Model
-{
-	[Flags]
-	public enum EntityEventType
-	{
-		Awake = 1,
-		Awake1 = 2,
-		Awake2 = 4,
-		Awake3 = 8,
-		Update = 16,
-		Load = 32,
-		LateUpdate = 64
-	}
-	
-
-	public class EntityTypeInfo
-	{
-		private readonly Dictionary<EntityEventType, IStaticMethod> infos = new Dictionary<EntityEventType, IStaticMethod>();
-
-		public void Add(EntityEventType type, IStaticMethod methodInfo)
-		{
-			try
-			{
-				this.infos.Add(type, methodInfo);
-			}
-			catch (Exception e)
-			{
-				throw new Exception($"Add EntityEventType MethodInfo Error: {type}", e);
-			}
-		}
-
-		public IStaticMethod Get(EntityEventType type)
-		{
-			IStaticMethod methodInfo;
-			this.infos.TryGetValue(type, out methodInfo);
-			return methodInfo;
-		}
-
-		public EntityEventType[] GetEntityEventTypes()
-		{
-			return this.infos.Keys.ToArray();
-		}
-
-		public override string ToString()
-		{
-			StringBuilder sb = new StringBuilder();
-			foreach (EntityEventType disposerEventType in this.infos.Keys.ToArray())
-			{
-				sb.Append($"{disposerEventType} {this.infos[disposerEventType].Name} ");
-			}
-			return sb.ToString();
-		}
-	}
-
-	public sealed class EntityEventManager
-	{
-		private readonly Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
-
-		private readonly Dictionary<EntityEventType, HashSet<Disposer>> disposers = new Dictionary<EntityEventType, HashSet<Disposer>>();
-
-		private readonly HashSet<Disposer> addDisposers = new HashSet<Disposer>();
-		private readonly HashSet<Disposer> removeDisposers = new HashSet<Disposer>();
-
-		private Dictionary<int, EntityTypeInfo> eventInfo;
-		private Dictionary<Type, int> typeToEntityEventId;
-
-#if !SERVER
-		private ILRuntime.Runtime.Enviorment.AppDomain appDomain;
-#endif
-
-		public EntityEventManager()
-		{
-			foreach (EntityEventType t in Enum.GetValues(typeof (EntityEventType)))
-			{
-				this.disposers.Add(t, new HashSet<Disposer>());
-			}
-		}
-
-		public void Register(string name, Assembly assembly)
-		{
-			this.assemblies[name] = assembly;
-
-			LoadAssemblyInfo();
-
-			this.Load();
-		}
-
-		public void LoadAssemblyInfo()
-		{
-			this.eventInfo = new Dictionary<int, EntityTypeInfo>();
-			this.typeToEntityEventId = new Dictionary<Type, int>();
-
-			Type[] types = DllHelper.GetMonoTypes();
-			List<string> allEntityType = Enum.GetNames(typeof(EntityEventType)).ToList();
-			foreach (Type type in types)
-			{
-				object[] attrs = type.GetCustomAttributes(typeof(EntityEventAttribute), true);
-				if (attrs.Length == 0)
-				{
-					continue;
-				}
-
-				EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;
-
-				int entityEventId = entityEventAttribute.ClassType;
-
-				this.typeToEntityEventId[type] = entityEventId;
-
-				if (!this.eventInfo.ContainsKey(entityEventId))
-				{
-					this.eventInfo.Add(entityEventId, new EntityTypeInfo());
-				}
-
-				MethodInfo[] methodInfos = type.GetMethods(
-					BindingFlags.Instance | BindingFlags.Static | BindingFlags.InvokeMethod | 
-					BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
-				foreach (MethodInfo methodInfo in methodInfos)
-				{
-					int n = methodInfo.GetParameters().Length;
-					if (methodInfo.IsStatic)
-					{
-						--n;
-					}
-
-					string sn = n > 0 ? $"{methodInfo.Name}{n}" : methodInfo.Name;
-					if (!allEntityType.Contains(sn))
-					{
-						continue;
-					}
-
-					EntityEventType t = EnumHelper.FromString<EntityEventType>(sn);
-					this.eventInfo[entityEventId].Add(t, new MonoStaticMethod(methodInfo));
-				}
-			}
-
-#if !SERVER
-			if (this.appDomain == null)
-			{
-				return;
-			}
-
-			IType[] ilTypes = this.appDomain.LoadedTypes.Values.ToArray();
-			foreach (IType itype in ilTypes)
-			{
-				Type type = itype.ReflectionType;
-				object[] attrs = type.GetCustomAttributes(typeof(EntityEventAttribute), true);
-				if (attrs.Length == 0)
-				{
-					continue;
-				}
-
-				EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;
-
-				int entityEventId = entityEventAttribute.ClassType;
-
-				if (!this.eventInfo.ContainsKey(entityEventId))
-				{
-					this.eventInfo.Add(entityEventId, new EntityTypeInfo());
-				}
-
-				foreach (IMethod methodInfo in itype.GetMethods())
-				{
-					int n = methodInfo.ParameterCount;
-					if (methodInfo.IsStatic)
-					{
-						--n;
-					}
-
-					string sn = n > 0 ? $"{methodInfo.Name}{n}" : methodInfo.Name;
-					if (!allEntityType.Contains(sn))
-					{
-						continue;
-					}
-
-					EntityEventType t = EnumHelper.FromString<EntityEventType>(sn);
-					this.eventInfo[entityEventId].Add(t, new ILStaticMethod(methodInfo, n));
-				}
-			}
-#endif
-		}
-
-
-#if !SERVER
-		public void RegisterILRuntime()
-		{
-			appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
-			ILRuntime.Runtime.Generated.CLRBindings.Initialize(appDomain);
-
-			GameObject code = (GameObject)Resources.Load("Code");
-			byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
-			byte[] mdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;
-
-			using (MemoryStream fs = new MemoryStream(assBytes))
-			using (MemoryStream p = new MemoryStream(mdbBytes))
-			{
-				appDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
-			}
-		}
-
-		public void RegisterILAdapter()
-		{
-			Assembly assembly = Game.EntityEventManager.GetAssembly("Model");
-
-			foreach (Type type in assembly.GetTypes())
-			{
-				object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
-				if (attrs.Length == 0)
-				{
-					continue;
-				}
-				object obj = Activator.CreateInstance(type);
-				CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
-				if (adaptor == null)
-				{
-					continue;
-				}
-				appDomain.RegisterCrossBindingAdaptor(adaptor);
-			}
-		}
-
-		public ILRuntime.Runtime.Enviorment.AppDomain AppDomain
-		{
-			get
-			{
-				return this.appDomain;
-			}
-		}
-#endif
-
-		private int GetEntityEventIdByType(Type type)
-		{
-			int entityEventId = 0;
-			this.typeToEntityEventId.TryGetValue(type, out entityEventId);
-			return entityEventId;
-		}
-
-		public void Add(Disposer disposer)
-		{
-			this.addDisposers.Add(disposer);
-		}
-
-		public void Remove(Disposer disposer)
-		{
-			this.removeDisposers.Add(disposer);
-		}
-
-		private void UpdateAddDisposer()
-		{
-			foreach (Disposer disposer in this.addDisposers)
-			{
-				EntityTypeInfo entityTypeInfo;
-				if (!this.eventInfo.TryGetValue(this.GetEntityEventIdByType(disposer.GetType()), out entityTypeInfo))
-				{
-					continue;
-				}
-
-				foreach (EntityEventType disposerEvent2Type in entityTypeInfo.GetEntityEventTypes())
-				{
-					this.disposers[disposerEvent2Type].Add(disposer);
-				}
-			}
-			this.addDisposers.Clear();
-		}
-
-		private void UpdateRemoveDisposer()
-		{
-			foreach (Disposer disposer in this.removeDisposers)
-			{
-				EntityTypeInfo entityTypeInfo;
-				if (!this.eventInfo.TryGetValue(this.GetEntityEventIdByType(disposer.GetType()), out entityTypeInfo))
-				{
-					continue;
-				}
-
-				foreach (EntityEventType disposerEvent2Type in entityTypeInfo.GetEntityEventTypes())
-				{
-					this.disposers[disposerEvent2Type].Remove(disposer);
-				}
-			}
-			this.removeDisposers.Clear();
-		}
-
-		public Assembly GetAssembly(string name)
-		{
-			return this.assemblies[name];
-		}
-
-		public Assembly[] GetAssemblies()
-		{
-			return this.assemblies.Values.ToArray();
-		}
-
-		private void Load()
-		{
-			HashSet<Disposer> list;
-			if (!this.disposers.TryGetValue(EntityEventType.Load, out list))
-			{
-				return;
-			}
-			foreach (Disposer disposer in list)
-			{
-				EntityTypeInfo entityTypeInfo = this.eventInfo[this.GetEntityEventIdByType(disposer.GetType())];
-				entityTypeInfo.Get(EntityEventType.Load).Run(disposer);
-			}
-		}
-
-		public void Awake(Disposer disposer)
-		{
-			EntityTypeInfo entityTypeInfo;
-			if (!this.eventInfo.TryGetValue(this.GetEntityEventIdByType(disposer.GetType()), out entityTypeInfo))
-			{
-				return;
-			}
-			entityTypeInfo.Get(EntityEventType.Awake)?.Run(disposer);
-		}
-
-		public void Awake(Disposer disposer, object p1)
-		{
-			EntityTypeInfo entityTypeInfo;
-			if (!this.eventInfo.TryGetValue(this.GetEntityEventIdByType(disposer.GetType()), out entityTypeInfo))
-			{
-				return;
-			}
-			entityTypeInfo.Get(EntityEventType.Awake1)?.Run(disposer, p1);
-		}
-
-		public void Awake(Disposer disposer, object p1, object p2)
-		{
-			EntityTypeInfo entityTypeInfo;
-			if (!this.eventInfo.TryGetValue(this.GetEntityEventIdByType(disposer.GetType()), out entityTypeInfo))
-			{
-				return;
-			}
-			entityTypeInfo.Get(EntityEventType.Awake2)?.Run(disposer, p1, p2);
-		}
-
-		public void Awake(Disposer disposer, object p1, object p2, object p3)
-		{
-			EntityTypeInfo entityTypeInfo;
-			if (!this.eventInfo.TryGetValue(this.GetEntityEventIdByType(disposer.GetType()), out entityTypeInfo))
-			{
-				return;
-			}
-			entityTypeInfo.Get(EntityEventType.Awake3)?.Run(disposer, p1, p2, p3);
-		}
-
-		public void Update()
-		{
-			UpdateAddDisposer();
-			UpdateRemoveDisposer();
-
-			HashSet<Disposer> list;
-			if (!this.disposers.TryGetValue(EntityEventType.Update, out list))
-			{
-				return;
-			}
-			foreach (Disposer disposer in list)
-			{
-				try
-				{
-					if (this.removeDisposers.Contains(disposer))
-					{
-						continue;
-					}
-					EntityTypeInfo entityTypeInfo = this.eventInfo[this.GetEntityEventIdByType(disposer.GetType())];
-					entityTypeInfo.Get(EntityEventType.Update).Run(disposer);
-				}
-				catch (Exception e)
-				{
-					Log.Error(e.ToString());
-				}
-			}
-		}
-
-		public void LateUpdate()
-		{
-			HashSet<Disposer> list;
-			if (!this.disposers.TryGetValue(EntityEventType.LateUpdate, out list))
-			{
-				return;
-			}
-			foreach (Disposer disposer in list)
-			{
-				try
-				{
-					EntityTypeInfo entityTypeInfo = this.eventInfo[this.GetEntityEventIdByType(disposer.GetType())];
-					entityTypeInfo.Get(EntityEventType.LateUpdate).Run(disposer);
-				}
-				catch (Exception e)
-				{
-					Log.Error(e.ToString());
-				}
-			}
-		}
-	}
-}

+ 22 - 0
Server/Model/Object/IAwake.cs

@@ -0,0 +1,22 @@
+namespace Model
+{
+	public interface IAwake
+	{
+		void Awake();
+	}
+
+	public interface IAwake<A>
+	{
+		void Awake(A a);
+	}
+
+	public interface IAwake<A, B>
+	{
+		void Awake(A a, B b);
+	}
+
+	public interface IAwake<A, B, C>
+	{
+		void Awake(A a, B b, C c);
+	}
+}

+ 7 - 0
Server/Model/Object/ILoad.cs

@@ -0,0 +1,7 @@
+namespace Model
+{
+	public interface ILoad
+	{
+		void Load();
+	}
+}

+ 7 - 0
Server/Model/Object/IUpdate.cs

@@ -0,0 +1,7 @@
+namespace Model
+{
+	public interface IUpdate
+	{
+		void Update();
+	}
+}

+ 9 - 0
Server/Model/Object/ObjectEventAttribute.cs

@@ -0,0 +1,9 @@
+using System;
+
+namespace Model
+{
+	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
+	public class ObjectEventAttribute: Attribute
+	{
+	}
+}

+ 262 - 0
Server/Model/Object/ObjectEvents.cs

@@ -0,0 +1,262 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using Base;
+
+namespace Model
+{
+	public interface IObjectEvent
+	{
+		Type Type();
+		void Set(object value);
+	}
+
+	public abstract class ObjectEvent<T> : IObjectEvent
+	{
+		private T value;
+
+		protected T Get()
+		{
+			return value;
+		}
+
+		public void Set(object v)
+		{
+			this.value = (T)v;
+		}
+
+		public Type Type()
+		{
+			return typeof(T);
+		}
+	}
+
+	public sealed class ObjectEvents
+	{
+		private static ObjectEvents instance;
+
+		public static ObjectEvents Instance
+		{
+			get
+			{
+				return instance ?? (instance = new ObjectEvents());
+			}
+		}
+
+		private readonly Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
+
+		private Dictionary<Type, IObjectEvent> disposerEvents;
+
+		private readonly HashSet<Disposer> updates = new HashSet<Disposer>();
+		private readonly HashSet<Disposer> loaders = new HashSet<Disposer>();
+
+		private readonly Queue<Disposer> adds = new Queue<Disposer>();
+		private readonly Queue<Disposer> removes = new Queue<Disposer>();
+
+		public void Register(string name, Assembly assembly)
+		{
+			this.assemblies[name] = assembly;
+
+			this.disposerEvents = new Dictionary<Type, IObjectEvent>();
+			foreach (Assembly ass in this.assemblies.Values)
+			{
+				Type[] types = ass.GetTypes();
+				foreach (Type type in types)
+				{
+					object[] attrs = type.GetCustomAttributes(typeof(ObjectEventAttribute), false);
+
+					if (attrs.Length == 0)
+					{
+						continue;
+					}
+
+					object obj = Activator.CreateInstance(type);
+					IObjectEvent objectEvent = obj as IObjectEvent;
+					if (objectEvent == null)
+					{
+						Log.Error($"组件事件没有继承IObjectEvent: {type.Name}");
+						continue;
+					}
+					this.disposerEvents[objectEvent.Type()] = objectEvent;
+				}
+			}
+
+			this.Load();
+		}
+
+		public Assembly GetAssembly(string name)
+		{
+			return this.assemblies[name];
+		}
+
+		public Assembly[] GetAssemblies()
+		{
+			return this.assemblies.Values.ToArray();
+		}
+
+		private void Load()
+		{
+			foreach (Disposer disposer in this.loaders)
+			{
+				if (!this.disposerEvents.TryGetValue(disposer.GetType(), out IObjectEvent objectEvent))
+				{
+					continue;
+				}
+				ILoad iLoader = objectEvent as ILoad;
+				if (iLoader == null)
+				{
+					continue;
+				}
+				objectEvent.Set(disposer);
+				iLoader.Load();
+			}
+		}
+
+		public void Add(Disposer disposer)
+		{
+			this.adds.Enqueue(disposer);
+		}
+
+		public void Remove(Disposer disposer)
+		{
+			this.removes.Enqueue(disposer);
+		}
+
+		public void UpdateAdd()
+		{
+			while (this.adds.Count > 0)
+			{
+				Disposer disposer = this.adds.Dequeue();
+				if (!this.disposerEvents.TryGetValue(disposer.GetType(), out IObjectEvent objectEvent))
+				{
+					continue;
+				}
+
+				IUpdate iUpdate = objectEvent as IUpdate;
+				if (iUpdate != null)
+				{
+					this.updates.Add(disposer);
+				}
+
+				ILoad iLoader = objectEvent as ILoad;
+				if (iLoader != null)
+				{
+					this.loaders.Add(disposer);
+				}
+			}
+		}
+
+		public void UpdateRemove()
+		{
+			while (this.removes.Count > 0)
+			{
+				Disposer disposer = this.removes.Dequeue();
+				if (!this.disposerEvents.TryGetValue(disposer.GetType(), out IObjectEvent objectEvent))
+				{
+					continue;
+				}
+
+				IUpdate iUpdate = objectEvent as IUpdate;
+				if (iUpdate != null)
+				{
+					this.updates.Remove(disposer);
+				}
+
+				ILoad iLoader = objectEvent as ILoad;
+				if (iLoader != null)
+				{
+					this.loaders.Remove(disposer);
+				}
+			}
+		}
+
+		public void Awake(Disposer disposer)
+		{
+			if (!this.disposerEvents.TryGetValue(disposer.GetType(), out IObjectEvent objectEvent))
+			{
+				return;
+			}
+			IAwake iAwake = objectEvent as IAwake;
+			if (iAwake == null)
+			{
+				return;
+			}
+			objectEvent.Set(disposer);
+			iAwake.Awake();
+		}
+
+		public void Awake<P1>(Disposer disposer, P1 p1)
+		{
+			if (!this.disposerEvents.TryGetValue(disposer.GetType(), out IObjectEvent objectEvent))
+			{
+				return;
+			}
+			IAwake<P1> iAwake = objectEvent as IAwake<P1>;
+			if (iAwake == null)
+			{
+				return;
+			}
+			objectEvent.Set(disposer);
+			iAwake.Awake(p1);
+		}
+
+		public void Awake<P1, P2>(Disposer disposer, P1 p1, P2 p2)
+		{
+			if (!this.disposerEvents.TryGetValue(disposer.GetType(), out IObjectEvent objectEvent))
+			{
+				return;
+			}
+			IAwake<P1, P2> iAwake = objectEvent as IAwake<P1, P2>;
+			if (iAwake == null)
+			{
+				return;
+			}
+			objectEvent.Set(disposer);
+			iAwake.Awake(p1, p2);
+		}
+
+		public void Awake<P1, P2, P3>(Disposer disposer, P1 p1, P2 p2, P3 p3)
+		{
+			if (!this.disposerEvents.TryGetValue(disposer.GetType(), out IObjectEvent objectEvent))
+			{
+				return;
+			}
+			IAwake<P1, P2, P3> iAwake = objectEvent as IAwake<P1, P2, P3>;
+			if (iAwake == null)
+			{
+				return;
+			}
+			objectEvent.Set(disposer);
+			iAwake.Awake(p1, p2, p3);
+		}
+
+		public void Update()
+		{
+			this.UpdateAdd();
+			this.UpdateRemove();
+
+			foreach (Disposer disposer in updates)
+			{
+				if (!this.disposerEvents.TryGetValue(disposer.GetType(), out IObjectEvent objectEvent))
+				{
+					continue;
+				}
+				IUpdate iUpdate = objectEvent as IUpdate;
+				if (iUpdate == null)
+				{
+					continue;
+				}
+				objectEvent.Set(disposer);
+				try
+				{
+					iUpdate.Update();
+				}
+				catch (Exception e)
+				{
+					Log.Error(e.ToString());
+				}
+			}
+		}
+	}
+}

+ 24 - 24
Server/Model/Other/EntityEventId.cs

@@ -1,30 +1,30 @@
 namespace Model
 namespace Model
 {
 {
-	public static class EntityEventId
+	public enum EntityEventId
 	{
 	{
-		public const int TimerComponent = 1;
-		public const int ClientConfigComponent = 2;
-		public const int EventComponent = 3;
-		public const int GameObjectComponent = 4;
-		public const int ILEventComponent = 5;
-		public const int MessageDispatherComponent = 6;
-		public const int NetInnerComponent = 7;
-		public const int NetOuterComponent = 8;
-		public const int RobotComponent = 9;
-		public const int UIComponent = 10;
-		public const int WWWAsync = 11;
-		public const int ILRuntimeComponent = 12;
-		public const int ResourcesComponent = 13;
-		public const int UnitComponent = 14;
+		TimerComponent = 1,
+		ClientConfigComponent = 2,
+		EventComponent = 3,
+		GameObjectComponent = 4,
+		ILEventComponent = 5,
+		MessageDispatherComponent = 6,
+		NetInnerComponent = 7,
+		NetOuterComponent = 8,
+		RobotComponent = 9,
+		UIComponent = 10,
+		WWWAsync = 11,
+		ILRuntimeComponent = 12,
+		ResourcesComponent = 13,
+		UnitComponent = 14,
 
 
-		public const int AppManagerComponent = 15;
-		public const int GateSessionKeyComponent = 16;
-		public const int OptionComponent = 17;
-		public const int StartConfigComponent = 18;
-		public const int LockComponent = 19;
-		public const int MasterComponent = 20;
-		public const int RealmGateAddressComponent = 21;
-		public const int UILobbyComponent = 22;
-		public const int BehaviorTreeComponent = 23;
+		AppManagerComponent = 15,
+		GateSessionKeyComponent = 16,
+		OptionComponent = 17,
+		StartConfigComponent = 18,
+		LockComponent = 19,
+		MasterComponent = 20,
+		RealmGateAddressComponent = 21,
+		UILobbyComponent = 22,
+		BehaviorTreeComponent = 23,
 	}
 	}
 }
 }

+ 6 - 2
Server/Model/Server.Model.csproj

@@ -94,13 +94,17 @@
     <Compile Include="Message\MessageInfo.cs" />
     <Compile Include="Message\MessageInfo.cs" />
     <Compile Include="Message\OpcodeHelper.cs" />
     <Compile Include="Message\OpcodeHelper.cs" />
     <Compile Include="Message\RpcException.cs" />
     <Compile Include="Message\RpcException.cs" />
+    <Compile Include="Object\ComponentDB.cs" />
     <Compile Include="Object\Component.cs" />
     <Compile Include="Object\Component.cs" />
     <Compile Include="Object\Disposer.cs" />
     <Compile Include="Object\Disposer.cs" />
     <Compile Include="Object\Entity.cs" />
     <Compile Include="Object\Entity.cs" />
-    <Compile Include="Object\EntityEventAttribute.cs" />
-    <Compile Include="Object\EntityEventManager.cs" />
+    <Compile Include="Object\IAwake.cs" />
+    <Compile Include="Object\ILoad.cs" />
+    <Compile Include="Object\IUpdate.cs" />
+    <Compile Include="Object\ObjectEventAttribute.cs" />
     <Compile Include="Object\EntityType.cs" />
     <Compile Include="Object\EntityType.cs" />
     <Compile Include="Object\Object.cs" />
     <Compile Include="Object\Object.cs" />
+    <Compile Include="Object\ObjectEvents.cs" />
     <Compile Include="Other\EntityEventId.cs" />
     <Compile Include="Other\EntityEventId.cs" />
     <Compile Include="Other\IInstanceMethod.cs" />
     <Compile Include="Other\IInstanceMethod.cs" />
     <Compile Include="Other\MonoMethod.cs" />
     <Compile Include="Other\MonoMethod.cs" />

+ 2 - 2
Server/Server.sln

@@ -1,7 +1,7 @@
 
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
+# Visual Studio 15
+VisualStudioVersion = 15.0.26430.14
 MinimumVisualStudioVersion = 10.0.40219.1
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Base", "Base\Server.Base.csproj", "{E5078EC6-2B0E-4711-BE8B-D99F69638316}"
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Base", "Base\Server.Base.csproj", "{E5078EC6-2B0E-4711-BE8B-D99F69638316}"
 EndProject
 EndProject