Jelajahi Sumber

使用MemoryPack也能加载dll运行

tanghai 2 tahun lalu
induk
melakukan
351ae94393

+ 15 - 0
ET.sln

@@ -53,6 +53,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Loader", "Unity\Unity
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNet.Loader", "DotNet\Loader\DotNet.Loader.csproj", "{1D5E890A-C9D5-45DF-B098-73DBE39EB311}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.AllCodes", "Unity\Unity.AllCodes.csproj", "{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -315,6 +317,18 @@ Global
 		{1D5E890A-C9D5-45DF-B098-73DBE39EB311}.Release|x64.Build.0 = Release|Any CPU
 		{1D5E890A-C9D5-45DF-B098-73DBE39EB311}.Release|x86.ActiveCfg = Release|Any CPU
 		{1D5E890A-C9D5-45DF-B098-73DBE39EB311}.Release|x86.Build.0 = Release|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Debug|x64.Build.0 = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Debug|x86.Build.0 = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Release|Any CPU.ActiveCfg = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Release|Any CPU.Build.0 = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Release|x64.ActiveCfg = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Release|x64.Build.0 = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Release|x86.ActiveCfg = Debug|Any CPU
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152}.Release|x86.Build.0 = Debug|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -342,6 +356,7 @@ Global
 		{DE4513D3-889B-5C52-8E9C-744C99AE7509} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
 		{9498BFB4-D9F5-C441-13E3-3F26F7700E29} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
 		{C109842F-01DA-64D4-DBF2-00C6449E459E} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
+		{BC8AF236-3AA6-2FE6-DCCB-E412FEC3C152} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {EABC01E3-3EB5-47EF-B46E-AAD8BB3585F1}

+ 1 - 1
Unity/Assets/Scripts/Core/Serialize/SerializeHelper.cs

@@ -7,7 +7,7 @@ namespace ET
 {
     public static class SerializeHelper
 	{
-		public const bool UseMemoryPack = false;
+		public const bool UseMemoryPack = true;
 		
 		public static object Deserialize(Type type, byte[] bytes, int index, int count)
 		{

+ 16 - 0
Unity/Assets/Scripts/Editor/AssetPostProcessor/OnGenerateCSProjectProcessor.cs

@@ -75,6 +75,22 @@ namespace ET
                     content = GenerateCustomProject(path, content,
                         @"Assets\Scripts\Codes\ModelView\**\*.cs %(RecursiveDir)%(FileName)%(Extension)");
                 }
+                
+                if (path.EndsWith("Unity.AllCodes.csproj"))
+                {
+                    content = content.Replace("<Compile Include=\"Assets\\Scripts\\Empty\\AllCodes\\Empty.cs\" />", string.Empty);
+                    content = content.Replace("<None Include=\"Assets\\Scripts\\Empty\\Hotfix\\Unity.AllCodes.asmdef\" />", string.Empty);
+
+                    content = GenerateCustomProject(path, content,
+                        @"Assets\Scripts\Codes\Model\Server\**\*.cs Server\%(RecursiveDir)%(FileName)%(Extension)",
+                        @"Assets\Scripts\Codes\Model\Client\**\*.cs Client\%(RecursiveDir)%(FileName)%(Extension)",
+                        @"Assets\Scripts\Codes\Model\Share\**\*.cs Share\%(RecursiveDir)%(FileName)%(Extension)",
+                        @"Assets\Scripts\Codes\Model\Generate\ClientServer\**\*.cs Generate\%(RecursiveDir)%(FileName)%(Extension)",
+                        @"Assets\Scripts\Codes\Hotfix\**\*.cs %(RecursiveDir)%(FileName)%(Extension)",
+                        @"Assets\Scripts\Codes\ModelView\**\*.cs %(RecursiveDir)%(FileName)%(Extension)",
+                        @"Assets\Scripts\Codes\HotfixView\**\*.cs %(RecursiveDir)%(FileName)%(Extension)"
+                        );
+                }
             }
             return content;
         }

+ 8 - 0
Unity/Assets/Scripts/Empty/AllCodes.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: b55a0b558962b416daebf36140117988
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Unity/Assets/Scripts/Empty/AllCodes/Empty.cs

@@ -0,0 +1 @@
+//用于自动生成工程项目的占位脚本,请勿移除或修改

+ 11 - 0
Unity/Assets/Scripts/Empty/AllCodes/Empty.cs.meta

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

+ 20 - 0
Unity/Assets/Scripts/Empty/AllCodes/Unity.AllCodes.asmdef

@@ -0,0 +1,20 @@
+{
+    "name": "Unity.AllCodes",
+    "rootNamespace": "ET",
+    "references": [
+        "Unity.ThirdParty",
+        "Unity.Core",
+        "Unity.Mathematics",
+        "Unity.Loader",
+        "MemoryPack"
+    ],
+    "includePlatforms": [],
+    "excludePlatforms": [],
+    "allowUnsafeCode": true,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
Unity/Assets/Scripts/Empty/AllCodes/Unity.AllCodes.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 53b9e14ab660a42008a62652f4983e8d
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 21 - 4
Unity/Assets/Scripts/Loader/CodeLoader.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Reflection;
 using UnityEngine;
+#pragma warning disable CS0162
 
 namespace ET
 {
@@ -49,14 +50,30 @@ namespace ET
 				}
 				else
 				{
-					assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Model.dll"));
-					pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Model.pdb"));
+					if (SerializeHelper.UseMemoryPack)
+					{
+						assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Unity.AllCodes", "Unity.AllCodes.dll"));
+						pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Unity.AllCodes", "Unity.AllCodes.pdb"));
+					}
+					else
+					{
+						assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Model.dll"));
+						pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Model.pdb"));
+					}
 				}
 			
 				this.model = Assembly.Load(assBytes, pdbBytes);
-				this.LoadHotfix();
+
+				if (SerializeHelper.UseMemoryPack)
+				{
+					Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, typeof(Init).Assembly, this.model);
+					EventSystem.Instance.Add(types);
+				}
+				else
+				{
+					this.LoadHotfix();
+				}
 			}
-			
 			IStaticMethod start = new StaticMethod(this.model, "ET.Entry", "Start");
 			start.Run();
 		}

+ 5 - 5
Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs

@@ -33,11 +33,11 @@ namespace ET
 			
 			ETTask.ExceptionHandler += Log.Error;
 
-			if (SerializeHelper.UseMemoryPack && !Define.EnableCodes)
-			{
-				Log.Error("MemoryPack must use ENABLE_CODES mode");
-				return;
-			}
+			//if (SerializeHelper.UseMemoryPack && !Define.EnableCodes)
+			//{
+			//	Log.Error("MemoryPack must use ENABLE_CODES mode");
+			//	return;
+			//}
 
 			Game.AddSingleton<CodeLoader>().Start();
 		}

File diff ditekan karena terlalu besar
+ 28 - 0
Unity/Unity.AllCodes.csproj


Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini