Przeglądaj źródła

EventSystem去掉了Assembly,简化了代码

tanghai 3 lat temu
rodzic
commit
669325ef73

+ 1 - 0
.gitignore

@@ -65,3 +65,4 @@ Server/.DS_Store
 /Unity/Unity.ModelView.csproj
 /Unity/Unity.ModelView.csproj
 
 
 /Unity/ProjectSettings/RiderScriptEditorPersistedState.asset
 /Unity/ProjectSettings/RiderScriptEditorPersistedState.asset
+/Unity/Unity.Core.csproj

+ 4 - 4
Apps/App/Program.cs

@@ -1,4 +1,5 @@
 using System;
 using System;
+using System.Collections.Generic;
 using System.Threading;
 using System.Threading;
 using CommandLine;
 using CommandLine;
 using NLog;
 using NLog;
@@ -21,10 +22,9 @@ namespace ET
 			
 			
 			try
 			try
 			{	
 			{	
-				Game.EventSystem.Add(typeof(Game).Assembly);
-				Game.EventSystem.Add(typeof(Unit).Assembly);
-				Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
-				Game.EventSystem.LoadAllAssembliesType();
+				Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, typeof(Unit).Assembly, DllHelper.GetHotfixAssembly());
+                    
+				Game.EventSystem.Add(types);
 				
 				
 				ProtobufHelper.Init();
 				ProtobufHelper.Init();
 				MongoHelper.Register(Game.EventSystem.GetTypes());
 				MongoHelper.Register(Game.EventSystem.GetTypes());

+ 7 - 2
Apps/Hotfix/Module/Console/ReloadDllConsoleHandler.cs

@@ -1,3 +1,6 @@
+using System;
+using System.Collections.Generic;
+
 namespace ET
 namespace ET
 {
 {
     [ConsoleHandler(ConsoleMode.ReloadDll)]
     [ConsoleHandler(ConsoleMode.ReloadDll)]
@@ -10,8 +13,10 @@ namespace ET
                 case ConsoleMode.ReloadDll:
                 case ConsoleMode.ReloadDll:
                     contex.Parent.RemoveComponent<ModeContex>();
                     contex.Parent.RemoveComponent<ModeContex>();
                     
                     
-                    Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
-                    Game.EventSystem.LoadAllAssembliesType();
+                    Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, typeof(Unit).Assembly, DllHelper.GetHotfixAssembly());
+                    
+                    Game.EventSystem.Add(types);
+                    
                     Game.EventSystem.Load();
                     Game.EventSystem.Load();
                     break;
                     break;
             }
             }

+ 6 - 3
Apps/Tool/Program.cs

@@ -1,4 +1,5 @@
 using System;
 using System;
+using System.Collections.Generic;
 using System.Threading;
 using System.Threading;
 using CommandLine;
 using CommandLine;
 using NLog;
 using NLog;
@@ -20,9 +21,11 @@ namespace ET
             SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
             SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
 			
 			
             try
             try
-            {		
-                Game.EventSystem.Add(typeof(Game).Assembly);
-				
+            {
+                Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly);
+                    
+                Game.EventSystem.Add(types);
+                
                 ProtobufHelper.Init();
                 ProtobufHelper.Init();
                 MongoHelper.Register(Game.EventSystem.GetTypes());
                 MongoHelper.Register(Game.EventSystem.GetTypes());
 				
 				

+ 24 - 0
Unity/Assets/Core/Helper/AssemblyHelper.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace ET
+{
+    public static class AssemblyHelper
+    {
+        public static Dictionary<string, Type> GetAssemblyTypes(params Assembly[] args)
+        {
+            Dictionary<string, Type> types = new Dictionary<string, Type>();
+
+            foreach (Assembly ass in args)
+            {
+                foreach (Type type in ass.GetTypes())
+                {
+                    types[type.FullName] = type;
+                }
+            }
+
+            return types;
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Core/Helper/AssemblyHelper.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 63fb0b4a59b5b7a499ae6e2b28f11ebb
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 21
Unity/Assets/Core/Object/EventSystem.cs

@@ -82,8 +82,6 @@ namespace ET
 
 
         private readonly Dictionary<long, Entity> allEntities = new();
         private readonly Dictionary<long, Entity> allEntities = new();
 
 
-        private readonly Dictionary<string, Assembly> assemblies = new();
-
         private readonly Dictionary<string, Type> allTypes = new();
         private readonly Dictionary<string, Type> allTypes = new();
 
 
         private readonly UnOrderMultiMapSet<Type, Type> types = new();
         private readonly UnOrderMultiMapSet<Type, Type> types = new();
@@ -217,25 +215,6 @@ namespace ET
             }
             }
         }
         }
 
 
-        public void Add(Assembly assembly)
-        {
-            this.assemblies[$"{assembly.GetName().Name}.dll"] = assembly;
-        }
-
-        public void LoadAllAssembliesType()
-        {
-            Dictionary<string, Type> addTypes = new Dictionary<string, Type>();
-
-            foreach (Assembly ass in this.assemblies.Values)
-            {
-                foreach (Type type in ass.GetTypes())
-                {
-                    addTypes[type.FullName] = type;
-                }
-            }
-            this.Add(addTypes);
-        }
-
         public HashSet<Type> GetTypes(Type systemAttributeType)
         public HashSet<Type> GetTypes(Type systemAttributeType)
         {
         {
             if (!this.types.ContainsKey(systemAttributeType))
             if (!this.types.ContainsKey(systemAttributeType))

+ 5 - 7
Unity/Assets/Mono/CodeLoader.cs

@@ -38,9 +38,9 @@ namespace ET
 					
 					
 					assembly = Assembly.Load(assBytes, pdbBytes);
 					assembly = Assembly.Load(assBytes, pdbBytes);
 
 
-					Game.EventSystem.Add(typeof(Game).Assembly);
-					Game.EventSystem.Add(this.assembly);
-					Game.EventSystem.LoadAllAssembliesType();
+
+					Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, this.assembly);
+					Game.EventSystem.Add(types);
 					
 					
 					IStaticMethod start = new MonoStaticMethod(assembly, "ET.Client.Entry", "Start");
 					IStaticMethod start = new MonoStaticMethod(assembly, "ET.Client.Entry", "Start");
 					start.Run();
 					start.Run();
@@ -83,11 +83,9 @@ namespace ET
 
 
 			Assembly hotfixAssembly = Assembly.Load(assBytes, pdbBytes);
 			Assembly hotfixAssembly = Assembly.Load(assBytes, pdbBytes);
 			
 			
-			Game.EventSystem.Add(typeof(Game).Assembly);
-			Game.EventSystem.Add(this.assembly);
-			Game.EventSystem.Add(hotfixAssembly);
+			Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, this.assembly, hotfixAssembly);
 			
 			
-			Game.EventSystem.LoadAllAssembliesType();
+			Game.EventSystem.Add(types);
 		}
 		}
 	}
 	}
 }
 }

Plik diff jest za duży
+ 0 - 28
Unity/Unity.Core.csproj


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików