Browse Source

DisposeEvent改成ComponentEvent,只有组件会有Awake Update等事件响应

tanghai 9 năm trước cách đây
mục cha
commit
80b81dddec
32 tập tin đã thay đổi với 60 bổ sung58 xóa
  1. 3 3
      Server/App/Program.cs
  2. 1 1
      Server/Controller/Component/RealmGateAddressComponent.cs
  3. 1 1
      Server/Controller/Message/M2A_ReloadHandler.cs
  4. 1 1
      Server/Model/Component/AppManagerComponent.cs
  5. 1 1
      Server/Model/Component/GateSessionKeyComponent.cs
  6. 1 1
      Server/Model/Component/OptionComponent.cs
  7. 1 1
      Server/Model/Component/StartConfigComponent.cs
  8. 1 1
      Server/Model/Component/Unit/LockComponent.cs
  9. 1 1
      Server/Model/Component/Unit/MasterComponent.cs
  10. 6 6
      Server/Model/Server.Model.csproj
  11. 2 2
      Unity/Assets/Editor/EditorInit.cs
  12. 1 1
      Unity/Assets/Scripts/Component/ClientConfigComponent.cs
  13. 1 1
      Unity/Assets/Scripts/Component/ConfigComponent.cs
  14. 2 2
      Unity/Assets/Scripts/Component/EventComponent.cs
  15. 1 1
      Unity/Assets/Scripts/Component/GameObjectComponent.cs
  16. 2 2
      Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
  17. 1 1
      Unity/Assets/Scripts/Component/NetInnerComponent.cs
  18. 1 1
      Unity/Assets/Scripts/Component/NetOuterComponent.cs
  19. 1 1
      Unity/Assets/Scripts/Component/RobotComponent.cs
  20. 1 1
      Unity/Assets/Scripts/Component/TimerComponent.cs
  21. 2 2
      Unity/Assets/Scripts/Component/UIComponent.cs
  22. 3 3
      Unity/Assets/Scripts/Entity/Game.cs
  23. 3 3
      Unity/Assets/Scripts/Init.cs
  24. 6 1
      Unity/Assets/Scripts/Object/Component.cs
  25. 2 2
      Unity/Assets/Scripts/Object/ComponentEventAttribute.cs
  26. 0 0
      Unity/Assets/Scripts/Object/ComponentEventAttribute.cs.meta
  27. 5 5
      Unity/Assets/Scripts/Object/ComponentEventManager.cs
  28. 0 0
      Unity/Assets/Scripts/Object/ComponentEventManager.cs.meta
  29. 1 4
      Unity/Assets/Scripts/Object/Disposer.cs
  30. 5 5
      Unity/Assets/Scripts/Object/Entity.cs
  31. 1 1
      Unity/Controller/Component/BenchmarkComponentE.cs
  32. 2 2
      Unity/Unity.csproj

+ 3 - 3
Server/App/Program.cs

@@ -11,8 +11,8 @@ namespace App
 		{
 			try
 			{
-				Game.DisposerEventManager.Register("Model", typeof(Game).Assembly);
-				Game.DisposerEventManager.Register("Controller", DllHelper.GetController());
+				Game.ComponentEventManager.Register("Model", typeof(Game).Assembly);
+				Game.ComponentEventManager.Register("Controller", DllHelper.GetController());
 
 				Options options = Game.Scene.AddComponent<OptionComponent>().Options;
 				StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;
@@ -68,7 +68,7 @@ namespace App
 				{
 					try
 					{
-						Game.DisposerEventManager.Update();
+						Game.ComponentEventManager.Update();
 					}
 					catch (Exception e)
 					{

+ 1 - 1
Server/Controller/Component/RealmGateAddressComponent.cs

@@ -2,7 +2,7 @@
 
 namespace Controller
 {
-	[DisposerEvent(typeof(RealmGateAddressComponent))]
+	[ComponentEvent(typeof(RealmGateAddressComponent))]
 	public static class RealmGateAddressComponentE
 	{
 		public static void Awake(this RealmGateAddressComponent component)

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

@@ -12,7 +12,7 @@ namespace Controller
 			A2M_Reload response = new A2M_Reload();
 			try
 			{
-				Game.DisposerEventManager.Register("Controller", DllHelper.GetController());
+				Game.ComponentEventManager.Register("Controller", DllHelper.GetController());
 				reply(response);
 			}
 			catch (Exception e)

+ 1 - 1
Server/Model/Component/AppManagerComponent.cs

@@ -6,7 +6,7 @@ using Base;
 
 namespace Model
 {
-	[DisposerEvent(typeof(AppManagerComponent))]
+	[ComponentEvent(typeof(AppManagerComponent))]
 	public class AppManagerComponent: Component
 	{
 		private readonly Dictionary<int, Process> processes = new Dictionary<int, Process>();

+ 1 - 1
Server/Model/Component/GateSessionKeyComponent.cs

@@ -3,7 +3,7 @@ using Base;
 
 namespace Model
 {
-	[DisposerEvent(typeof(GateSessionKeyComponent))]
+	[ComponentEvent(typeof(GateSessionKeyComponent))]
 	public class GateSessionKeyComponent : Component
 	{
 		private TimerComponent timerComponent;

+ 1 - 1
Server/Model/Component/OptionComponent.cs

@@ -3,7 +3,7 @@ using CommandLine;
 
 namespace Model
 {
-	[DisposerEvent(typeof(OptionComponent))]
+	[ComponentEvent(typeof(OptionComponent))]
 	public class OptionComponent : Component
 	{
 		public Options Options { get; } = new Options();

+ 1 - 1
Server/Model/Component/StartConfigComponent.cs

@@ -5,7 +5,7 @@ using Base;
 
 namespace Model
 {
-	[DisposerEvent(typeof(StartConfigComponent))]
+	[ComponentEvent(typeof(StartConfigComponent))]
 	public class StartConfigComponent: Component
 	{
 		private readonly List<StartConfig> allConfigs = new List<StartConfig>();

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

@@ -15,7 +15,7 @@ namespace Model
 	/// <summary>
 	/// 分布式锁组件,Unit对象可能在不同进程上有镜像,访问该对象的时候需要对他加锁
 	/// </summary>
-	[DisposerEvent(typeof(LockComponent))]
+	[ComponentEvent(typeof(LockComponent))]
 	public class LockComponent: Component
 	{
 		private LockStatus status = LockStatus.LockedNot;

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

@@ -16,7 +16,7 @@ namespace Model
 		}
 	}
 
-	[DisposerEvent(typeof(MasterComponent))]
+	[ComponentEvent(typeof(MasterComponent))]
 	public class MasterComponent : Component
 	{
 		private readonly List<string> slavesAddress = new List<string>();

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

@@ -170,14 +170,14 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Object\Component.cs">
       <Link>Object\Component.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Object\Disposer.cs">
-      <Link>Object\Disposer.cs</Link>
+    <Compile Include="..\..\Unity\Assets\Scripts\Object\ComponentEventAttribute.cs">
+      <Link>Object\ComponentEventAttribute.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Object\DisposerEventAttribute.cs">
-      <Link>Object\DisposerEventAttribute.cs</Link>
+    <Compile Include="..\..\Unity\Assets\Scripts\Object\ComponentEventManager.cs">
+      <Link>Object\ComponentEventManager.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Object\DisposerEventManager.cs">
-      <Link>Object\DisposerEventManager.cs</Link>
+    <Compile Include="..\..\Unity\Assets\Scripts\Object\Disposer.cs">
+      <Link>Object\Disposer.cs</Link>
     </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Object\Entity.cs">
       <Link>Object\Entity.cs</Link>

+ 2 - 2
Unity/Assets/Editor/EditorInit.cs

@@ -10,7 +10,7 @@ namespace MyEditor
 	{
 		static EditorInit()
 		{
-			Game.DisposerEventManager.Register("Editor", typeof(EditorInit).Assembly);
+			Game.ComponentEventManager.Register("Editor", typeof(EditorInit).Assembly);
 			EditorApplication.update += Update;
 		}
 
@@ -23,7 +23,7 @@ namespace MyEditor
 
 			try
 			{
-				Game.DisposerEventManager.Update();
+				Game.ComponentEventManager.Update();
 			}
 			catch (Exception e)
 			{

+ 1 - 1
Unity/Assets/Scripts/Component/ClientConfigComponent.cs

@@ -3,7 +3,7 @@ using Base;
 
 namespace Model
 {
-	[DisposerEvent(typeof(ClientConfigComponent))]
+	[ComponentEvent(typeof(ClientConfigComponent))]
 	public class ClientConfigComponent : Component
     {
 		public StartConfig Config { get; private set; }

+ 1 - 1
Unity/Assets/Scripts/Component/ConfigComponent.cs

@@ -11,7 +11,7 @@ namespace Model
 
 		private void Load()
 		{
-			Assembly assembly = Game.DisposerEventManager.GetAssembly("Base");
+			Assembly assembly = Game.ComponentEventManager.GetAssembly("Base");
 
 			this.allConfig = new Dictionary<Type, ICategory>();
 			Type[] types = assembly.GetTypes();

+ 2 - 2
Unity/Assets/Scripts/Component/EventComponent.cs

@@ -8,7 +8,7 @@ namespace Model
 	/// <summary>
 	/// 事件分发
 	/// </summary>
-	[DisposerEvent(typeof(EventComponent))]
+	[ComponentEvent(typeof(EventComponent))]
 	public class EventComponent: Component
 	{
 		private Dictionary<EventIdType, List<object>> allEvents;
@@ -21,7 +21,7 @@ namespace Model
 		private void Load()
 		{
 			this.allEvents = new Dictionary<EventIdType, List<object>>();
-			Assembly[] assemblies = Game.DisposerEventManager.GetAssemblies();
+			Assembly[] assemblies = Game.ComponentEventManager.GetAssemblies();
 			foreach (Assembly assembly in assemblies)
 			{
 				Type[] types = assembly.GetTypes();

+ 1 - 1
Unity/Assets/Scripts/Component/GameObjectComponent.cs

@@ -2,7 +2,7 @@
 
 namespace Model
 {
-	[DisposerEvent(typeof(GameObjectComponent))]
+	[ComponentEvent(typeof(GameObjectComponent))]
 	public class GameObjectComponent : Component
     {
 		public GameObject GameObject { get; private set; }

+ 2 - 2
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs

@@ -8,7 +8,7 @@ namespace Model
 	/// <summary>
 	/// 消息分发组件
 	/// </summary>
-	[DisposerEvent(typeof(MessageDispatherComponent))]
+	[ComponentEvent(typeof(MessageDispatherComponent))]
 	public class MessageDispatherComponent: Component
 	{
 		private AppType AppType;
@@ -26,7 +26,7 @@ namespace Model
 			this.handlers = new Dictionary<ushort, List<IMHandler>>();
 			this.messageOpcode = new Dictionary<Type, MessageAttribute>();
 
-			Assembly[] assemblies = Game.DisposerEventManager.GetAssemblies();
+			Assembly[] assemblies = Game.ComponentEventManager.GetAssemblies();
 
 			foreach (Assembly assembly in assemblies)
 			{

+ 1 - 1
Unity/Assets/Scripts/Component/NetInnerComponent.cs

@@ -3,7 +3,7 @@ using Base;
 
 namespace Model
 {
-	[DisposerEvent(typeof(NetInnerComponent))]
+	[ComponentEvent(typeof(NetInnerComponent))]
 	public class NetInnerComponent : NetworkComponent
 	{
 		private readonly Dictionary<string, Session> adressSessions = new Dictionary<string, Session>();

+ 1 - 1
Unity/Assets/Scripts/Component/NetOuterComponent.cs

@@ -2,7 +2,7 @@
 
 namespace Model
 {
-	[DisposerEvent(typeof(NetOuterComponent))]
+	[ComponentEvent(typeof(NetOuterComponent))]
 	public class NetOuterComponent : NetworkComponent
 	{
 		private void Awake()

+ 1 - 1
Unity/Assets/Scripts/Component/RobotComponent.cs

@@ -1,6 +1,6 @@
 namespace Model
 {
-	[DisposerEvent(typeof(RobotComponent))]
+	[ComponentEvent(typeof(RobotComponent))]
 	public class RobotComponent : Component
     {
 		private void Awake()

+ 1 - 1
Unity/Assets/Scripts/Component/TimerComponent.cs

@@ -12,7 +12,7 @@ namespace Model
 		public TaskCompletionSource<bool> tcs;
 	}
 
-	[DisposerEvent(typeof(TimerComponent))]
+	[ComponentEvent(typeof(TimerComponent))]
 	public class TimerComponent: Component
 	{
 		private readonly Dictionary<long, Timer> timers = new Dictionary<long, Timer>();

+ 2 - 2
Unity/Assets/Scripts/Component/UIComponent.cs

@@ -10,7 +10,7 @@ namespace Model
 	/// <summary>
 	/// 管理所有UI
 	/// </summary>
-	[DisposerEvent(typeof(UIComponent))]
+	[ComponentEvent(typeof(UIComponent))]
 	public class UIComponent: Component
 	{
         private UI Root;
@@ -50,7 +50,7 @@ namespace Model
 		{
 			this.UiTypes = new Dictionary<UIType, IUIFactory>();
 
-			Assembly[] assemblies = Game.DisposerEventManager.GetAssemblies();
+			Assembly[] assemblies = Game.ComponentEventManager.GetAssemblies();
 			foreach (Assembly assembly in assemblies)
 			{
 				Type[] types = assembly.GetTypes();

+ 3 - 3
Unity/Assets/Scripts/Entity/Game.cs

@@ -9,7 +9,7 @@ namespace Base
 	{
 		private static readonly HashSet<Disposer> disposers = new HashSet<Disposer>();
 
-		private static DisposerEventManager disposerEventManager;
+		private static ComponentEventManager componentEventManager;
 
 		private static Scene scene;
 
@@ -36,11 +36,11 @@ namespace Base
 			disposers.Clear();
 		}
 
-		public static DisposerEventManager DisposerEventManager
+		public static ComponentEventManager ComponentEventManager
 		{
 			get
 			{
-				return disposerEventManager ?? (disposerEventManager = new DisposerEventManager());
+				return componentEventManager ?? (componentEventManager = new ComponentEventManager());
 			}
 		}
 

+ 3 - 3
Unity/Assets/Scripts/Init.cs

@@ -8,8 +8,8 @@ namespace Model
 	{
 		private void Start()
 		{
-			Game.DisposerEventManager.Register("Model", typeof(Game).Assembly);
-			Game.DisposerEventManager.Register("Controller", DllHelper.GetController());
+			Game.ComponentEventManager.Register("Model", typeof(Game).Assembly);
+			Game.ComponentEventManager.Register("Controller", DllHelper.GetController());
 
 			Game.Scene.AddComponent<EventComponent>().Run(EventIdType.InitSceneStart);
 		}
@@ -18,7 +18,7 @@ namespace Model
 		{
 			try
 			{
-				Game.DisposerEventManager.Update();
+				Game.ComponentEventManager.Update();
 			}
 			catch (Exception e)
 			{

+ 6 - 1
Unity/Assets/Scripts/Object/Component.cs

@@ -1,4 +1,5 @@
-using MongoDB.Bson.Serialization.Attributes;
+using Base;
+using MongoDB.Bson.Serialization.Attributes;
 
 namespace Model
 {
@@ -15,10 +16,12 @@ namespace Model
 
 		protected Component()
 		{
+			Game.ComponentEventManager.Add(this);
 		}
 
 		protected Component(long id): base(id)
 		{
+			Game.ComponentEventManager.Add(this);
 		}
 
 		public T GetComponent<T>() where T: Component
@@ -34,6 +37,8 @@ namespace Model
 			}
 
 			base.Dispose();
+
+			Game.ComponentEventManager.Remove(this);
 		}
 	}
 }

+ 2 - 2
Unity/Assets/Scripts/Object/DisposerEventAttribute.cs → Unity/Assets/Scripts/Object/ComponentEventAttribute.cs

@@ -3,11 +3,11 @@
 namespace Model
 {
 	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-	public class DisposerEventAttribute: Attribute
+	public class ComponentEventAttribute: Attribute
 	{
 		public Type ClassType;
 
-		public DisposerEventAttribute(Type classType)
+		public ComponentEventAttribute(Type classType)
 		{
 			this.ClassType = classType;
 		}

+ 0 - 0
Unity/Assets/Scripts/Object/DisposerEventAttribute.cs.meta → Unity/Assets/Scripts/Object/ComponentEventAttribute.cs.meta


+ 5 - 5
Unity/Assets/Scripts/Object/DisposerEventManager.cs → Unity/Assets/Scripts/Object/ComponentEventManager.cs

@@ -57,7 +57,7 @@ namespace Model
 		}
 	}
 
-	public sealed class DisposerEventManager
+	public sealed class ComponentEventManager
 	{
 		private readonly Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
 
@@ -65,7 +65,7 @@ namespace Model
 
 		private Dictionary<Type, DisposerTypeInfo> eventInfo;
 
-		public DisposerEventManager()
+		public ComponentEventManager()
 		{
 			foreach (DisposerEventType t in Enum.GetValues(typeof(DisposerEventType)))
 			{
@@ -84,15 +84,15 @@ namespace Model
 				Type[] types = ass.GetTypes();
 				foreach (Type type in types)
 				{
-					object[] attrs = type.GetCustomAttributes(typeof(DisposerEventAttribute), true);
+					object[] attrs = type.GetCustomAttributes(typeof(ComponentEventAttribute), true);
 					if (attrs.Length == 0)
 					{
 						continue;
 					}
 
-					DisposerEventAttribute DisposerEventAttribute = attrs[0] as DisposerEventAttribute;
+					ComponentEventAttribute componentEventAttribute = attrs[0] as ComponentEventAttribute;
 
-					Type type2 = DisposerEventAttribute.ClassType;
+					Type type2 = componentEventAttribute.ClassType;
 
 					if (!this.eventInfo.ContainsKey(type2))
 					{

+ 0 - 0
Unity/Assets/Scripts/Object/DisposerEventManager.cs.meta → Unity/Assets/Scripts/Object/ComponentEventManager.cs.meta


+ 1 - 4
Unity/Assets/Scripts/Object/Disposer.cs

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

+ 5 - 5
Unity/Assets/Scripts/Object/Entity.cs

@@ -66,7 +66,7 @@ namespace Model
 
 			this.components.Add(component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.DisposerEventManager.Awake(component);
+			Game.ComponentEventManager.Awake(component);
 			return component;
 		}
 
@@ -87,7 +87,7 @@ namespace Model
 
 			this.components.Add(component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.DisposerEventManager.Awake(component, p1);
+			Game.ComponentEventManager.Awake(component, p1);
 			return component;
 		}
 
@@ -108,7 +108,7 @@ namespace Model
 
 			this.components.Add(component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.DisposerEventManager.Awake(component, p1, p2);
+			Game.ComponentEventManager.Awake(component, p1, p2);
 			return component;
 		}
 
@@ -130,7 +130,7 @@ namespace Model
 
 			this.components.Add(component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.DisposerEventManager.Awake(component, p1, p2, p3);
+			Game.ComponentEventManager.Awake(component, p1, p2, p3);
 			return component;
 		}
 
@@ -147,7 +147,7 @@ namespace Model
 			}
 			this.components.Add(component);
 			this.componentDict.Add(component.GetType(), component);
-			Game.DisposerEventManager.Awake(component);
+			Game.ComponentEventManager.Awake(component);
 		}
 
 		public void RemoveComponent<K>() where K : Component

+ 1 - 1
Unity/Controller/Component/BenchmarkComponentE.cs

@@ -4,7 +4,7 @@ using Model;
 
 namespace Controller
 {
-	[DisposerEvent(typeof(BenchmakComponent))]
+	[ComponentEvent(typeof(BenchmakComponent))]
 	public static class BenchmakComponentE
 	{
 		private static async void Awake(this BenchmakComponent component, string address)

+ 2 - 2
Unity/Unity.csproj

@@ -136,8 +136,8 @@
     <Compile Include="Assets\Scripts\Message\RpcException.cs" />
     <Compile Include="Assets\Scripts\Object\Component.cs" />
     <Compile Include="Assets\Scripts\Object\Disposer.cs" />
-    <Compile Include="Assets\Scripts\Object\DisposerEventAttribute.cs" />
-    <Compile Include="Assets\Scripts\Object\DisposerEventManager.cs" />
+    <Compile Include="Assets\Scripts\Object\ComponentEventAttribute.cs" />
+    <Compile Include="Assets\Scripts\Object\ComponentEventManager.cs" />
     <Compile Include="Assets\Scripts\Object\Entity.cs" />
     <Compile Include="Assets\Scripts\Object\EntityType.cs" />
     <Compile Include="Assets\Scripts\Object\IAwake.cs" />