Sfoglia il codice sorgente

修复mono模式下运行错误

tanghai 8 anni fa
parent
commit
5d457f8652

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

@@ -68,29 +68,26 @@ namespace Model
 			this.assemblies[name] = assembly;
 
 			this.disposerEvents.Clear();
-			foreach (Assembly ass in this.assemblies.Values)
+			Type[] types = DllHelper.GetMonoTypes();
+			foreach (Type type in types)
 			{
-				Type[] types = ass.GetTypes();
-				foreach (Type type in types)
+				object[] attrs = type.GetCustomAttributes(typeof(ObjectEventAttribute), false);
+
+				if (attrs.Length == 0)
 				{
-					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;
+					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();
 		}
 

+ 3 - 7
Unity/Assets/Scripts/Helper/DllHelper.cs

@@ -59,15 +59,11 @@ namespace Model
 			return ObjectEvents.Instance.Get("Hotfix").GetTypes();
 #endif
 		}
-
+		
 		public static Type[] GetMonoTypes()
 		{
-			List<Type> types = new List<Type>();
-			foreach (Assembly assembly in ObjectEvents.Instance.GetAll())
-			{
-				types.AddRange(assembly.GetTypes());
-			}
-			return types.ToArray();
+			Assembly model = ObjectEvents.Instance.Get("Model");
+			return model.GetTypes();
 		}
 
 #if ILRuntime

+ 1 - 0
Unity/Assets/Scripts/Init.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.IO;
 using System.Reflection;
 using System.Threading;

+ 12 - 0
Unity/Hotfix/Init.cs

@@ -36,6 +36,18 @@ namespace Hotfix
 			}
 		}
 
+		public static void LateUpdate()
+		{
+			try
+			{
+				ObjectEvents.Instance.LateUpdate();
+			}
+			catch (Exception e)
+			{
+				Log.Error(e.ToString());
+			}
+		}
+
 		public static void OnApplicationQuit()
 		{
 			Hotfix.Close();

+ 1 - 1
Unity/ProjectSettings/ProjectSettings.asset

@@ -566,7 +566,7 @@ PlayerSettings:
   webGLUseWasm: 0
   webGLCompressionFormat: 1
   scriptingDefineSymbols:
-    1: NET45;ILRuntime
+    1: NET45
   platformArchitecture:
     iOS: 2
   scriptingBackend:

+ 6 - 9
Unity/Unity.csproj

@@ -12,15 +12,12 @@
     <ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
     <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
-    <TargetFrameworkProfile>
-    </TargetFrameworkProfile>
-    <CompilerResponseFile>
-    </CompilerResponseFile>
+    <TargetFrameworkProfile></TargetFrameworkProfile>
+    <CompilerResponseFile></CompilerResponseFile>
     <UnityProjectType>Game:1</UnityProjectType>
     <UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
     <UnityVersion>2017.1.0f3</UnityVersion>
-    <RootNamespace>
-    </RootNamespace>
+    <RootNamespace></RootNamespace>
     <LangVersion>6</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -415,9 +412,11 @@
     <Compile Include="Assets\Scripts\Base\Object\AssemblyManager.cs" />
     <Compile Include="Assets\Scripts\Base\Object\Component.cs" />
     <Compile Include="Assets\Scripts\Base\Object\ComponentDB.cs" />
+    <Compile Include="Assets\Scripts\Base\Object\ComponentFactory.cs" />
     <Compile Include="Assets\Scripts\Base\Object\Disposer.cs" />
     <Compile Include="Assets\Scripts\Base\Object\Entity.cs" />
     <Compile Include="Assets\Scripts\Base\Object\EntityEventAttribute.cs" />
+    <Compile Include="Assets\Scripts\Base\Object\EntityFactory.cs" />
     <Compile Include="Assets\Scripts\Base\Object\EntityType.cs" />
     <Compile Include="Assets\Scripts\Base\Object\IAwake.cs" />
     <Compile Include="Assets\Scripts\Base\Object\ILateUpdate.cs" />
@@ -427,8 +426,6 @@
     <Compile Include="Assets\Scripts\Base\Object\Object.cs" />
     <Compile Include="Assets\Scripts\Base\Object\ObjectEventAttribute.cs" />
     <Compile Include="Assets\Scripts\Base\Object\ObjectEvents.cs" />
-    <Compile Include="Assets\Scripts\Base\Object\ComponentFactory.cs" />
-    <Compile Include="Assets\Scripts\Base\Object\EntityFactory.cs" />
     <Compile Include="Assets\Scripts\Base\QueueDictionary.cs" />
     <Compile Include="Assets\Scripts\Base\TryLocker.cs" />
     <Compile Include="Assets\Scripts\Base\UI\LayerNames.cs" />
@@ -540,4 +537,4 @@
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="GenerateTargetFrameworkMonikerAttribute" />
-</Project>
+</Project>