Przeglądaj źródła

去掉一些mono层的泛型方法,避免热更层调用AOT问题

tanghai 7 lat temu
rodzic
commit
87c40877b6

+ 1 - 1
Unity/Assets/Scripts/Entity/Hotfix.cs

@@ -57,7 +57,7 @@ namespace ETModel
 			Game.Scene.GetComponent<ResourcesComponent>().LoadBundle($"code.unity3d");
 #if ILRuntime
 			this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
-			GameObject code = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("code.unity3d", "Code");
+			GameObject code = (GameObject)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("code.unity3d", "Code");
 			byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
 			byte[] mdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;
 

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

@@ -24,7 +24,7 @@ namespace ETModel
 						await bundleDownloaderComponent.StartAsync();
 					}
 					Game.Scene.GetComponent<ResourcesComponent>().LoadOneBundle("StreamingAssets");
-					ResourcesComponent.AssetBundleManifestObject = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<AssetBundleManifest>("StreamingAssets", "AssetBundleManifest");
+					ResourcesComponent.AssetBundleManifestObject = (AssetBundleManifest)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("StreamingAssets", "AssetBundleManifest");
 				}
 				catch (Exception e)
 				{

+ 11 - 10
Unity/Assets/Scripts/Module/AssetsBundle/ResourcesComponent.cs

@@ -84,7 +84,7 @@ namespace ETModel
 			this.resourceCache.Clear();
 		}
 
-		public K GetAsset<K>(string bundleName, string prefab) where K : class
+		public UnityEngine.Object GetAsset(string bundleName, string prefab)
 		{
 			string path = $"{bundleName}/{prefab}".ToLower();
 
@@ -93,13 +93,12 @@ namespace ETModel
 			{
 				throw new Exception($"not found asset: {path}");
 			}
-
-			K k = resource as K;
-			if (k == null)
+			
+			if (resource == null)
 			{
-				throw new Exception($"asset type error, type: {k.GetType().Name}, path: {path}");
+				throw new Exception($"asset type error, path: {path}");
 			}
-			return k;
+			return resource;
 		}
 
 		public void UnloadBundle(string assetBundleName)
@@ -189,8 +188,9 @@ namespace ETModel
 
 			if (!Define.IsAsync)
 			{
+				string[] realPath = null;
 #if UNITY_EDITOR
-				string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
+				realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
 				foreach (string s in realPath)
 				{
 					string assetName = Path.GetFileNameWithoutExtension(s);
@@ -200,8 +200,8 @@ namespace ETModel
 				}
 
 				this.bundles[assetBundleName] = new ABInfo(assetBundleName, null);
-				return;
 #endif
+				return;
 			}
 
 			AssetBundle assetBundle = AssetBundle.LoadFromFile(Path.Combine(PathHelper.AppHotfixResPath, assetBundleName));
@@ -263,8 +263,9 @@ namespace ETModel
 
 			if (!Define.IsAsync)
 			{
+				string[] realPath = null;
 #if UNITY_EDITOR
-				string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
+				realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
 				foreach (string s in realPath)
 				{
 					string assetName = Path.GetFileNameWithoutExtension(s);
@@ -274,8 +275,8 @@ namespace ETModel
 				}
 
 				this.bundles[assetBundleName] = new ABInfo(assetBundleName, null);
-				return;
 #endif
+				return;
 			}
 
 			AssetBundle assetBundle;

+ 1 - 1
Unity/Assets/Scripts/Module/Config/ConfigHelper.cs

@@ -9,7 +9,7 @@ namespace ETModel
 		{
 			try
 			{
-				GameObject config = Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("config.unity3d", "Config");
+				GameObject config = (GameObject)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("config.unity3d", "Config");
 				string configStr = config.Get<TextAsset>(key).text;
 				return configStr;
 			}

+ 1 - 1
Unity/Assets/Scripts/Module/FrameSync/UnitFactory.cs

@@ -7,7 +7,7 @@ namespace ETModel
         public static Unit Create(long id)
         {
 	        ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
-	        GameObject bundleGameObject = resourcesComponent.GetAsset<GameObject>("Unit.unity3d", "Unit");
+	        GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
 	        GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
 	        
             UnitComponent unitComponent = Game.Scene.GetComponent<UnitComponent>();

+ 16 - 6
Unity/Assets/Scripts/Other/ReferenceCollector.cs

@@ -18,7 +18,7 @@ public class ReferenceCollectorDataComparer: IComparer<ReferenceCollectorData>
 {
 	public int Compare(ReferenceCollectorData x, ReferenceCollectorData y)
 	{
-		return String.Compare(x.key, y.key, StringComparison.Ordinal);
+		return string.Compare(x.key, y.key, StringComparison.Ordinal);
 	}
 }
 
@@ -32,7 +32,7 @@ public class ReferenceCollector: MonoBehaviour, ISerializationCallbackReceiver
 	public void Add(string key, Object obj)
 	{
 		SerializedObject serializedObject = new SerializedObject(this);
-		var dataProperty = serializedObject.FindProperty("data");
+		SerializedProperty dataProperty = serializedObject.FindProperty("data");
 		int i;
 		for (i = 0; i < data.Count; i++)
 		{
@@ -43,13 +43,13 @@ public class ReferenceCollector: MonoBehaviour, ISerializationCallbackReceiver
 		}
 		if (i != data.Count)
 		{
-			var element = dataProperty.GetArrayElementAtIndex(i);
+			SerializedProperty element = dataProperty.GetArrayElementAtIndex(i);
 			element.FindPropertyRelative("gameObject").objectReferenceValue = obj;
 		}
 		else
 		{
 			dataProperty.InsertArrayElementAtIndex(i);
-			var element = dataProperty.GetArrayElementAtIndex(i);
+			SerializedProperty element = dataProperty.GetArrayElementAtIndex(i);
 			element.FindPropertyRelative("key").stringValue = key;
 			element.FindPropertyRelative("gameObject").objectReferenceValue = obj;
 		}
@@ -61,7 +61,7 @@ public class ReferenceCollector: MonoBehaviour, ISerializationCallbackReceiver
 	public void Remove(string key)
 	{
 		SerializedObject serializedObject = new SerializedObject(this);
-		var dataProperty = serializedObject.FindProperty("data");
+		SerializedProperty dataProperty = serializedObject.FindProperty("data");
 		int i;
 		for (i = 0; i < data.Count; i++)
 		{
@@ -109,6 +109,16 @@ public class ReferenceCollector: MonoBehaviour, ISerializationCallbackReceiver
 		return dictGo as T;
 	}
 
+	public Object Get(string key)
+	{
+		Object dictGo;
+		if (!dict.TryGetValue(key, out dictGo))
+		{
+			return null;
+		}
+		return dictGo;
+	}
+
 	public void OnBeforeSerialize()
 	{
 	}
@@ -116,7 +126,7 @@ public class ReferenceCollector: MonoBehaviour, ISerializationCallbackReceiver
 	public void OnAfterDeserialize()
 	{
 		dict.Clear();
-		foreach (var referenceCollectorData in data)
+		foreach (ReferenceCollectorData referenceCollectorData in data)
 		{
 			if (!dict.ContainsKey(referenceCollectorData.key))
 			{

+ 2 - 4
Unity/Assets/ThirdParty/ILRuntime/Generated/CLRBindings.cs

@@ -13,10 +13,6 @@ namespace ILRuntime.Runtime.Generated
         {
             System_NotImplementedException_Binding.Register(app);
             System_String_Binding.Register(app);
-            ETModel_Define_Binding.Register(app);
-            System_Exception_Binding.Register(app);
-            System_Collections_IDictionary_Binding.Register(app);
-            System_Object_Binding.Register(app);
             LitJson_JsonMapper_Binding.Register(app);
             UnityEngine_LayerMask_Binding.Register(app);
             UnityEngine_Input_Binding.Register(app);
@@ -54,9 +50,11 @@ namespace ILRuntime.Runtime.Generated
             System_Type_Binding.Register(app);
             System_Reflection_MemberInfo_Binding.Register(app);
             System_Activator_Binding.Register(app);
+            System_Exception_Binding.Register(app);
             ETModel_GameObjectHelper_Binding.Register(app);
             UnityEngine_TextAsset_Binding.Register(app);
             //UnityEngine_Resources_Binding.Register(app);
+            System_Object_Binding.Register(app);
             System_Collections_Generic_HashSet_1_ILTypeInstance_Binding.Register(app);
             System_Linq_Enumerable_Binding.Register(app);
             System_Collections_Generic_HashSet_1_ILTypeInstance_Binding_Enumerator_Binding.Register(app);

+ 0 - 46
Unity/Assets/ThirdParty/ILRuntime/Generated/ETModel_Define_Binding.cs

@@ -1,46 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-using ILRuntime.CLR.TypeSystem;
-using ILRuntime.CLR.Method;
-using ILRuntime.Runtime.Enviorment;
-using ILRuntime.Runtime.Intepreter;
-using ILRuntime.Runtime.Stack;
-using ILRuntime.Reflection;
-using ILRuntime.CLR.Utils;
-
-namespace ILRuntime.Runtime.Generated
-{
-    unsafe class ETModel_Define_Binding
-    {
-        public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
-        {
-            BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
-            MethodBase method;
-            FieldInfo field;
-            Type[] args;
-            Type type = typeof(ETModel.Define);
-
-            field = type.GetField("IsILRuntime", flag);
-            app.RegisterCLRFieldGetter(field, get_IsILRuntime_0);
-            app.RegisterCLRFieldSetter(field, set_IsILRuntime_0);
-
-
-        }
-
-
-
-        static object get_IsILRuntime_0(ref object o)
-        {
-            return ETModel.Define.IsILRuntime;
-        }
-        static void set_IsILRuntime_0(ref object o, object v)
-        {
-            ETModel.Define.IsILRuntime = (System.Boolean)v;
-        }
-
-
-    }
-}

+ 0 - 12
Unity/Assets/ThirdParty/ILRuntime/Generated/ETModel_Define_Binding.cs.meta

@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: 7cb7a597359ae20438b94e329dadff48
-timeCreated: 1520320313
-licenseType: Free
-MonoImporter:
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 9 - 29
Unity/Assets/ThirdParty/ILRuntime/Generated/ETModel_ResourcesComponent_Binding.cs

@@ -25,34 +25,9 @@ namespace ILRuntime.Runtime.Generated
             args = new Type[]{typeof(System.String)};
             method = type.GetMethod("LoadBundle", flag, null, args, null);
             app.RegisterCLRMethodRedirection(method, LoadBundle_0);
-            Dictionary<string, List<MethodInfo>> genericMethods = new Dictionary<string, List<MethodInfo>>();
-            List<MethodInfo> lst = null;                    
-            foreach(var m in type.GetMethods())
-            {
-                if(m.IsGenericMethodDefinition)
-                {
-                    if (!genericMethods.TryGetValue(m.Name, out lst))
-                    {
-                        lst = new List<MethodInfo>();
-                        genericMethods[m.Name] = lst;
-                    }
-                    lst.Add(m);
-                }
-            }
-            args = new Type[]{typeof(UnityEngine.GameObject)};
-            if (genericMethods.TryGetValue("GetAsset", out lst))
-            {
-                foreach(var m in lst)
-                {
-                    if(m.GetParameters().Length == 2)
-                    {
-                        method = m.MakeGenericMethod(args);
-                        app.RegisterCLRMethodRedirection(method, GetAsset_1);
-
-                        break;
-                    }
-                }
-            }
+            args = new Type[]{typeof(System.String), typeof(System.String)};
+            method = type.GetMethod("GetAsset", flag, null, args, null);
+            app.RegisterCLRMethodRedirection(method, GetAsset_1);
             args = new Type[]{typeof(System.String)};
             method = type.GetMethod("UnloadBundle", flag, null, args, null);
             app.RegisterCLRMethodRedirection(method, UnloadBundle_2);
@@ -95,8 +70,13 @@ namespace ILRuntime.Runtime.Generated
             instance_of_this_method = (ETModel.ResourcesComponent)typeof(ETModel.ResourcesComponent).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
             __intp.Free(ptr_of_this_method);
 
-            var result_of_this_method = instance_of_this_method.GetAsset<UnityEngine.GameObject>(bundleName, prefab);
+            var result_of_this_method = instance_of_this_method.GetAsset(bundleName, prefab);
 
+            object obj_result_of_this_method = result_of_this_method;
+            if(obj_result_of_this_method is CrossBindingAdaptorType)
+            {    
+                return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance);
+            }
             return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
         }
 

+ 0 - 59
Unity/Assets/ThirdParty/ILRuntime/Generated/System_Collections_IDictionary_Binding.cs

@@ -1,59 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-using ILRuntime.CLR.TypeSystem;
-using ILRuntime.CLR.Method;
-using ILRuntime.Runtime.Enviorment;
-using ILRuntime.Runtime.Intepreter;
-using ILRuntime.Runtime.Stack;
-using ILRuntime.Reflection;
-using ILRuntime.CLR.Utils;
-
-namespace ILRuntime.Runtime.Generated
-{
-    unsafe class System_Collections_IDictionary_Binding
-    {
-        public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
-        {
-            BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
-            MethodBase method;
-            FieldInfo field;
-            Type[] args;
-            Type type = typeof(System.Collections.IDictionary);
-            args = new Type[]{typeof(System.Object)};
-            method = type.GetMethod("get_Item", flag, null, args, null);
-            app.RegisterCLRMethodRedirection(method, get_Item_0);
-
-
-        }
-
-
-        static StackObject* get_Item_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
-        {
-            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
-            StackObject* ptr_of_this_method;
-            StackObject* __ret = ILIntepreter.Minus(__esp, 2);
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
-            System.Object key = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
-            System.Collections.IDictionary instance_of_this_method;
-            instance_of_this_method = (System.Collections.IDictionary)typeof(System.Collections.IDictionary).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-            var result_of_this_method = instance_of_this_method[key];
-
-            object obj_result_of_this_method = result_of_this_method;
-            if(obj_result_of_this_method is CrossBindingAdaptorType)
-            {    
-                return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance, true);
-            }
-            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method, true);
-        }
-
-
-
-    }
-}

+ 0 - 12
Unity/Assets/ThirdParty/ILRuntime/Generated/System_Collections_IDictionary_Binding.cs.meta

@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: 43dc474baabf6314fba305f92238ffcb
-timeCreated: 1520320313
-licenseType: Free
-MonoImporter:
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 23
Unity/Assets/ThirdParty/ILRuntime/Generated/System_Exception_Binding.cs

@@ -22,9 +22,6 @@ namespace ILRuntime.Runtime.Generated
             FieldInfo field;
             Type[] args;
             Type type = typeof(System.Exception);
-            args = new Type[]{};
-            method = type.GetMethod("get_Data", flag, null, args, null);
-            app.RegisterCLRMethodRedirection(method, get_Data_0);
 
             args = new Type[]{typeof(System.String)};
             method = type.GetConstructor(flag, null, args, null);
@@ -36,26 +33,6 @@ namespace ILRuntime.Runtime.Generated
         }
 
 
-        static StackObject* get_Data_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
-        {
-            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
-            StackObject* ptr_of_this_method;
-            StackObject* __ret = ILIntepreter.Minus(__esp, 1);
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
-            System.Exception instance_of_this_method;
-            instance_of_this_method = (System.Exception)typeof(System.Exception).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-            var result_of_this_method = instance_of_this_method.Data;
-
-            object obj_result_of_this_method = result_of_this_method;
-            if(obj_result_of_this_method is CrossBindingAdaptorType)
-            {    
-                return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance);
-            }
-            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
-        }
-
 
         static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
         {

+ 1 - 1
Unity/Hotfix/Module/Config/ConfigHelper.cs

@@ -10,7 +10,7 @@ namespace ETHotfix
 		{
 			try
 			{
-				GameObject config = ETModel.Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("config.unity3d", "Config");
+				GameObject config = (GameObject)ETModel.Game.Scene.GetComponent<ResourcesComponent>().GetAsset("config.unity3d", "Config");
 				string configStr = config.Get<TextAsset>(key).text;
 				return configStr;
 			}

+ 1 - 1
Unity/Hotfix/UI/UILobby/Factory/UILobbyFactory.cs

@@ -13,7 +13,7 @@ namespace ETHotfix
 	        {
 				ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent<ResourcesComponent>();
 		        resourcesComponent.LoadBundle($"{type}.unity3d");
-				GameObject bundleGameObject = resourcesComponent.GetAsset<GameObject>($"{type}.unity3d", $"{type}");
+				GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset($"{type}.unity3d", $"{type}");
 				GameObject lobby = UnityEngine.Object.Instantiate(bundleGameObject);
 				lobby.layer = LayerMask.NameToLayer(LayerNames.UI);
 				UI ui = ComponentFactory.Create<UI, GameObject>(lobby);

+ 1 - 1
Unity/Hotfix/UI/UILogin/Factory/UILoginFactory.cs

@@ -13,7 +13,7 @@ namespace ETHotfix
 	        {
 				ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent<ResourcesComponent>();
 				resourcesComponent.LoadBundle($"{type}.unity3d");
-				GameObject bundleGameObject = resourcesComponent.GetAsset<GameObject>($"{type}.unity3d", $"{type}");
+				GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset($"{type}.unity3d", $"{type}");
 				GameObject login = UnityEngine.Object.Instantiate(bundleGameObject);
 				login.layer = LayerMask.NameToLayer(LayerNames.UI);
 		        UI ui = ComponentFactory.Create<UI, GameObject>(login);

+ 0 - 2
Unity/Unity.csproj

@@ -353,7 +353,6 @@
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\ETModel_CanvasConfig_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\ETModel_Component_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\ETModel_ComponentFactory_Binding.cs" />
-    <Compile Include="Assets\ThirdParty\ILRuntime\Generated\ETModel_Define_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\ETModel_Disposer_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\ETModel_DoubleMap_2_UInt16_Type_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\ETModel_Entity_Binding.cs" />
@@ -413,7 +412,6 @@
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Collections_Generic_List_1_UnitInfo_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Collections_Generic_List_1_UnitInfo_Binding_Enumerator__t.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Collections_Generic_Queue_1_ILTypeInstance_Binding.cs" />
-    <Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Collections_IDictionary_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Exception_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_IDisposable_Binding.cs" />
     <Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Linq_Enumerable_Binding.cs" />