Просмотр исходного кода

hotfix程序集单独管理,因为hotfix程序集中的类型会由Hotfix中的ObjectEvent扫描所有类型

tanghai 8 лет назад
Родитель
Сommit
9fe416ef71

+ 1 - 1
Unity/Assets/Res/Code/Hotfix.mdb.bytes.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 23845562ede90da4c8bc06908a4c6667
-timeCreated: 1504515298
+timeCreated: 1504579131
 licenseType: Free
 TextScriptImporter:
   userData: 

+ 19 - 20
Unity/Assets/Scripts/Base/Object/ObjectEvents.cs

@@ -43,6 +43,8 @@ namespace Model
 			}
 		}
 
+		public Assembly HotfixAssembly;
+
 		private readonly Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
 
 		private readonly Dictionary<Type, IObjectEvent> disposerEvents = new Dictionary<Type, IObjectEvent>();
@@ -67,29 +69,26 @@ namespace Model
 		{
 			this.assemblies[name] = assembly;
 
-			if (name != "Model")
-			{
-				return;
-			}
-
-			Type[] types = assembly.GetTypes();
-			foreach (Type type in types)
+			foreach (Assembly ass in this.assemblies.Values)
 			{
-				object[] attrs = type.GetCustomAttributes(typeof(ObjectEventAttribute), false);
-
-				if (attrs.Length == 0)
+				foreach (Type type in ass.GetTypes())
 				{
-					continue;
-				}
-
-				object obj = Activator.CreateInstance(type);
-				IObjectEvent objectEvent = obj as IObjectEvent;
-				if (objectEvent == null)
-				{
-					Log.Error($"组件事件没有继承IObjectEvent: {type.Name}");
-					continue;
+					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.disposerEvents[objectEvent.Type()] = objectEvent;
 			}
 		}
 

+ 1 - 1
Unity/Assets/Scripts/Helper/DllHelper.cs

@@ -46,7 +46,7 @@ namespace Model
 
 			return appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
 #else
-			return ObjectEvents.Instance.Get("Hotfix").GetTypes();
+			return ObjectEvents.Instance.HotfixAssembly.GetTypes();
 #endif
 		}
 		

+ 2 - 4
Unity/Assets/Scripts/Init.cs

@@ -50,10 +50,8 @@ namespace Model
 				this.onApplicationQuit = new ILStaticMethod("Hotfix.Init", "OnApplicationQuit", 0);
 #else
 				Log.Debug("run in mono mode");
-				ObjectEvents.Instance.Add("Model", typeof(Init).Assembly);
-				Assembly hotfix = DllHelper.LoadHotfixAssembly();
-				ObjectEvents.Instance.Add("Hotfix", hotfix);
-				Type hotfixInit = hotfix.GetType("Hotfix.Init");
+				ObjectEvents.Instance.HotfixAssembly = DllHelper.LoadHotfixAssembly();
+				Type hotfixInit = ObjectEvents.Instance.HotfixAssembly.GetType("Hotfix.Init");
 				this.start = new MonoStaticMethod(hotfixInit, "Start");
 				this.update = new MonoStaticMethod(hotfixInit, "Update");
 				this.lateUpdate = new MonoStaticMethod(hotfixInit, "LateUpdate");

+ 1 - 3
Unity/Hotfix/Base/Object/ObjectEvents.cs

@@ -61,9 +61,7 @@ namespace Hotfix
 		{
 			instance = null;
 		}
-
-
-
+		
 		public ObjectEvents()
 		{
 			Type[] types = DllHelper.GetHotfixTypes();