Преглед изворни кода

1.Codes拆成AllHotfix跟AllModel两个程序集,方便热重载
2.ENABLE_CODES改成ENABLE_DLL,跟ET7区分一下,不然很多人反应不过来
3.更新HybridCLR到3.02

tanghai пре 2 година
родитељ
комит
9c674096c3

+ 6 - 7
Book/1.1运行指南.md

@@ -54,19 +54,18 @@
 
 05. 打开Unity菜单ET/BuildTool CodeMode选择Client Server, 点击ReGenerateProjectFiles。  
 
-06. 打开ET.sln, 编译Unity.Codes工程,Model Hotfix ModelView HotfixView加载失败没有关系   
+06. 打开ET.sln, 编译Unity.AllHotfix工程,Model Hotfix ModelView HotfixView加载失败没有关系   
 
 07. Unity中双击Scenes目录中的Init场景,点击Play即可运行   
 
 08. 默认是一个人匹配,如果需要多人匹配,修改LSConstValue中的MatchCount即可  
 
-09. 帧同步打包过程注意,同上面打包一样,区别是为了方便测试,我让打出来的包直接加载了Unity/Temp/Bin/Debug/Codes.dll。代码在CodeLoader.cs 46行,大家真正打包应该加载ab包中的dll资源,要使用上面注释的代码  
+09. 帧同步打包过程注意,同上面打包一样,区别是为了方便测试,我让打出来的包直接加载了Unity/Temp/Bin/Debug/Model.dll跟Hotfix.dll。代码在CodeLoader.cs 42跟76行,大家真正打包应该加载ab包中的dll资源,要使用上面注释的代码  
 
-# ENABLE_CODES模式,帧同步跟状态同步的demo含义完全相反,下面是以状态同步举例  
-1. 上面是把逻辑打成了一个dll,unity加载dll运行,这样Unity Editor将无法引用逻辑代码。如果Editor需要用到逻辑代码,可以开启ENABLE_CODES模式  
-2. Unity菜单ET/ChangeDefine/Add ENABLE_CODES即可添加ENABLE_CODES宏,这样逻辑代码将作为Editor模式放到Unity中,Editor代码就可以引用到逻辑代码  
-3. ENABLE_CODES模式不需要再BuildModelAndHotfix,直接点击Play就能运行  
-4. ENABLE_CODES只能在编辑器模式下使用,打包必须去掉ENABLE_CODES宏
+# ENABLE_DLL模式  
+1. 该模式用于逻辑全热更新,还有热重载, 默认就是使用该模式  
+2. 在Unity菜单ET->ChangeDefines中开启关闭  
+3. 逻辑打成了一个Model.dll跟Hotfix.dll,unity加载dll运行,这样Unity Editor将无法引用逻辑代码。如果Editor需要用到逻辑代码,可以关闭ENABLE_DLL模式  
 
 
 # 测试状态同步demo

+ 30 - 15
ET.sln

@@ -41,10 +41,12 @@ 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.Codes", "Unity\Unity.Codes.csproj", "{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Share.SourceGenerator", "Share\Share.SourceGenerator\Share.SourceGenerator.csproj", "{B29C9195-BEE7-4291-B57C-990425CDEF81}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.AllModel", "Unity\Unity.AllModel.csproj", "{B274D5FA-24BE-0EF2-8374-77D88F882F8D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.AllHotfix", "Unity\Unity.AllHotfix.csproj", "{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -247,18 +249,6 @@ 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
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Debug|x64.Build.0 = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Debug|x86.Build.0 = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Release|Any CPU.ActiveCfg = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Release|Any CPU.Build.0 = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Release|x64.ActiveCfg = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Release|x64.Build.0 = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Release|x86.ActiveCfg = Debug|Any CPU
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944}.Release|x86.Build.0 = Debug|Any CPU
 		{B29C9195-BEE7-4291-B57C-990425CDEF81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{B29C9195-BEE7-4291-B57C-990425CDEF81}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{B29C9195-BEE7-4291-B57C-990425CDEF81}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -271,6 +261,30 @@ Global
 		{B29C9195-BEE7-4291-B57C-990425CDEF81}.Release|x64.Build.0 = Release|Any CPU
 		{B29C9195-BEE7-4291-B57C-990425CDEF81}.Release|x86.ActiveCfg = Release|Any CPU
 		{B29C9195-BEE7-4291-B57C-990425CDEF81}.Release|x86.Build.0 = Release|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Debug|x64.Build.0 = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Debug|x86.Build.0 = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Release|Any CPU.ActiveCfg = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Release|Any CPU.Build.0 = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Release|x64.ActiveCfg = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Release|x64.Build.0 = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Release|x86.ActiveCfg = Debug|Any CPU
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D}.Release|x86.Build.0 = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Debug|x64.Build.0 = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Debug|x86.Build.0 = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Release|Any CPU.ActiveCfg = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Release|Any CPU.Build.0 = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Release|x64.ActiveCfg = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Release|x64.Build.0 = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Release|x86.ActiveCfg = Debug|Any CPU
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A}.Release|x86.Build.0 = Debug|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -292,8 +306,9 @@ 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}
-		{C8CDB918-7F4F-0E46-C7AA-900F18D8C944} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
 		{B29C9195-BEE7-4291-B57C-990425CDEF81} = {1272AF7B-A962-4BA4-8A9C-FFA7E131A0AC}
+		{B274D5FA-24BE-0EF2-8374-77D88F882F8D} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
+		{152061A0-80F4-0ADA-C8E3-F8EAEC23405A} = {914C77C9-212A-4DD0-8D9A-074620E77FAA}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {EABC01E3-3EB5-47EF-B46E-AAD8BB3585F1}

+ 0 - 0
Unity/Assets/Scripts/Codes.meta → Unity/Assets/Scripts/AllHotfix.meta


+ 0 - 0
Unity/Assets/Scripts/Codes/Empty.cs → Unity/Assets/Scripts/AllHotfix/Empty.cs


+ 0 - 0
Unity/Assets/Scripts/Codes/Empty.cs.meta → Unity/Assets/Scripts/AllHotfix/Empty.cs.meta


+ 23 - 0
Unity/Assets/Scripts/AllHotfix/Unity.AllHotfix.asmdef

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

+ 0 - 0
Unity/Assets/Scripts/Codes/Unity.Codes.asmdef.meta → Unity/Assets/Scripts/AllHotfix/Unity.AllHotfix.asmdef.meta


+ 8 - 0
Unity/Assets/Scripts/AllModel.meta

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

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

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

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

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

+ 2 - 2
Unity/Assets/Scripts/Codes/Unity.Codes.asmdef → Unity/Assets/Scripts/AllModel/Unity.AllModel.asmdef

@@ -1,5 +1,5 @@
 {
-    "name": "Unity.Codes",
+    "name": "Unity.AllModel",
     "rootNamespace": "ET",
     "references": [
         "Unity.ThirdParty",
@@ -15,7 +15,7 @@
     "precompiledReferences": [],
     "autoReferenced": true,
     "defineConstraints": [
-        "ENABLE_CODES"
+        "ENABLE_DLL"
     ],
     "versionDefines": [],
     "noEngineReferences": false

+ 7 - 0
Unity/Assets/Scripts/AllModel/Unity.AllModel.asmdef.meta

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

+ 0 - 1
Unity/Assets/Scripts/Core/Module/Network/KService.cs

@@ -294,7 +294,6 @@ namespace ET
                             }
 
                             string realAddress = null;
-                            remoteConn = BitConverter.ToUInt32(this.cache, 1);
                             if (messageLength > 9)
                             {
                                 realAddress = this.cache.ToStr(9, messageLength - 9);

+ 68 - 11
Unity/Assets/Scripts/Editor/AssetPostProcessor/OnGenerateCSProjectProcessor.cs

@@ -8,20 +8,29 @@ namespace ET
 {
     public class OnGenerateCSProjectProcessor: AssetPostprocessor
     {
+        private static string[] deleteFile = new string[] 
+        { 
+            "Library/ScriptAssemblies/Unity.AllModel.dll", 
+            "Library/ScriptAssemblies/Unity.AllHotfix.dll",
+            "Library/ScriptAssemblies/Unity.AllModel.pdb", 
+            "Library/ScriptAssemblies/Unity.AllHotfix.pdb", 
+        };
+        
         public static string OnGeneratedCSProject(string path, string content)
         {
             if (path.EndsWith("Unity.Core.csproj"))
             {
                 return GenerateCustomProject(path, content);
             }
+            
+            GlobalConfig globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
 
-            if (path.EndsWith("Unity.Codes.csproj"))
+            if (path.EndsWith("Unity.AllModel.csproj"))
             {
-                if (!Define.EnableCodes)
+                if (!Define.EnableDll)
                 {
                     return content;
                 }
-                GlobalConfig globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
                 if (globalConfig.BuildType == BuildType.Release)
                 {
                     content = content.Replace("<Optimize>false</Optimize>", "<Optimize>true</Optimize>");
@@ -37,10 +46,7 @@ namespace ET
                             @"Assets\Scripts\Model\Client\**\*.cs Model\Client\%(RecursiveDir)%(FileName)%(Extension)",
                             @"Assets\Scripts\Model\Share\**\*.cs Model\Share\%(RecursiveDir)%(FileName)%(Extension)",
                             @"Assets\Scripts\Model\Generate\Client\**\*.cs Model\Generate\%(RecursiveDir)%(FileName)%(Extension)",
-                            @"Assets\Scripts\Hotfix\Client\**\*.cs Hotfix\Client\%(RecursiveDir)%(FileName)%(Extension)",
-                            @"Assets\Scripts\Hotfix\Share\**\*.cs Hotfix\Share\%(RecursiveDir)%(FileName)%(Extension)",
                             @"Assets\Scripts\ModelView\Client\**\*.cs ModelView\Client\%(RecursiveDir)%(FileName)%(Extension)",
-                            @"Assets\Scripts\HotfixView\Client\**\*.cs HotfixView\Client\%(RecursiveDir)%(FileName)%(Extension)"
                         };
                         break;
                     case CodeMode.ClientServer:
@@ -50,10 +56,52 @@ namespace ET
                             @"Assets\Scripts\Model\Client\**\*.cs Model\Client\%(RecursiveDir)%(FileName)%(Extension)",
                             @"Assets\Scripts\Model\Share\**\*.cs Model\Share\%(RecursiveDir)%(FileName)%(Extension)",
                             @"Assets\Scripts\Model\Generate\ClientServer\**\*.cs Model\Generate\%(RecursiveDir)%(FileName)%(Extension)",
+                            @"Assets\Scripts\ModelView\Client\**\*.cs ModelView\Client\%(RecursiveDir)%(FileName)%(Extension)",
+                        };
+                        break;
+                }
+
+                content = GenerateCustomProject(path, content, files);
+                content = content.Replace("<Target Name=\"AfterBuild\" />",
+                    "   <Target Name=\"PostBuild\" AfterTargets=\"PostBuildEvent\">\n" +
+                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).dll\" DestinationFiles=\"$(ProjectDir)/{Define.CodeDir}/Model.dll.bytes\" ContinueOnError=\"false\" />\n" +
+                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).pdb\" DestinationFiles=\"$(ProjectDir)/{Define.CodeDir}/Model.pdb.bytes\" ContinueOnError=\"false\" />\n" +
+                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).dll\" DestinationFiles=\"$(ProjectDir)/{Define.BuildOutputDir}/Model.dll\" ContinueOnError=\"false\" />\n" +
+                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).pdb\" DestinationFiles=\"$(ProjectDir)/{Define.BuildOutputDir}/Model.pdb\" ContinueOnError=\"false\" />\n" +
+                    "   </Target>\n");
+                return content;
+            }
+            
+            if (path.EndsWith("Unity.AllHotfix.csproj"))
+            {
+                if (!Define.EnableDll)
+                {
+                    return content;
+                }
+                
+                if (globalConfig.BuildType == BuildType.Release)
+                {
+                    content = content.Replace("<Optimize>false</Optimize>", "<Optimize>true</Optimize>");
+                    content = content.Replace(";DEBUG;", ";");
+                }
+
+                string[] files = Array.Empty<string>();
+                switch (globalConfig.CodeMode)
+                {
+                    case CodeMode.Client:
+                        files = new[]
+                        {
+                            @"Assets\Scripts\Hotfix\Client\**\*.cs Hotfix\Client\%(RecursiveDir)%(FileName)%(Extension)",
+                            @"Assets\Scripts\Hotfix\Share\**\*.cs Hotfix\Share\%(RecursiveDir)%(FileName)%(Extension)",
+                            @"Assets\Scripts\HotfixView\Client\**\*.cs HotfixView\Client\%(RecursiveDir)%(FileName)%(Extension)"
+                        };
+                        break;
+                    case CodeMode.ClientServer:
+                        files = new[]
+                        {
                             @"Assets\Scripts\Hotfix\Client\**\*.cs Hotfix\Client\%(RecursiveDir)%(FileName)%(Extension)",
                             @"Assets\Scripts\Hotfix\Server\**\*.cs Hotfix\Server\%(RecursiveDir)%(FileName)%(Extension)",
                             @"Assets\Scripts\Hotfix\Share\**\*.cs Hotfix\Share\%(RecursiveDir)%(FileName)%(Extension)",
-                            @"Assets\Scripts\ModelView\Client\**\*.cs ModelView\Client\%(RecursiveDir)%(FileName)%(Extension)",
                             @"Assets\Scripts\HotfixView\Client\**\*.cs HotfixView\Client\%(RecursiveDir)%(FileName)%(Extension)"
                         };
                         break;
@@ -62,13 +110,22 @@ namespace ET
                 content = GenerateCustomProject(path, content, files);
                 content = content.Replace("<Target Name=\"AfterBuild\" />",
                     "   <Target Name=\"PostBuild\" AfterTargets=\"PostBuildEvent\">\n" +
-                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).dll\" DestinationFiles=\"$(ProjectDir)/{Define.CodeDir}/Codes.dll.bytes\" ContinueOnError=\"false\" />\n" +
-                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).pdb\" DestinationFiles=\"$(ProjectDir)/{Define.CodeDir}/Codes.pdb.bytes\" ContinueOnError=\"false\" />\n" +
-                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).dll\" DestinationFiles=\"$(ProjectDir)/{Define.BuildOutputDir}/Codes.dll\" ContinueOnError=\"false\" />\n" +
-                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).pdb\" DestinationFiles=\"$(ProjectDir)/{Define.BuildOutputDir}/Codes.pdb\" ContinueOnError=\"false\" />\n" +
+                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).dll\" DestinationFiles=\"$(ProjectDir)/{Define.CodeDir}/Hotfix.dll.bytes\" ContinueOnError=\"false\" />\n" +
+                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).pdb\" DestinationFiles=\"$(ProjectDir)/{Define.CodeDir}/Hotfix.pdb.bytes\" ContinueOnError=\"false\" />\n" +
+                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).dll\" DestinationFiles=\"$(ProjectDir)/{Define.BuildOutputDir}/Hotfix.dll\" ContinueOnError=\"false\" />\n" +
+                    $"       <Copy SourceFiles=\"$(TargetDir)/$(TargetName).pdb\" DestinationFiles=\"$(ProjectDir)/{Define.BuildOutputDir}/Hotfix.pdb\" ContinueOnError=\"false\" />\n" +
                     "   </Target>\n");
             }
 
+
+            foreach (string file in deleteFile)
+            {
+                if (File.Exists(file))
+                {
+                    File.Delete(file);    
+                }
+            }
+
             return content;
         }
 

+ 7 - 7
Unity/Assets/Scripts/Editor/BuildEditor/BuildHelper.cs

@@ -31,17 +31,17 @@ namespace ET
         }
 
               
-#if ENABLE_CODES
-        [MenuItem("ET/ChangeDefine/Remove ENABLE_CODES")]
-        public static void RemoveEnableCodes()
+#if ENABLE_DLL
+        [MenuItem("ET/ChangeDefine/Remove ENABLE_DLL")]
+        public static void RemoveEnableDll()
         {
-            EnableDefineSymbols("ENABLE_CODES", false);
+            EnableDefineSymbols("ENABLE_DLL", false);
         }
 #else
-        [MenuItem("ET/ChangeDefine/Add ENABLE_CODES")]
-        public static void AddEnableCodes()
+        [MenuItem("ET/ChangeDefine/Add ENABLE_DLL")]
+        public static void AddEnableDll()
         {
-            EnableDefineSymbols("ENABLE_CODES", true);
+            EnableDefineSymbols("ENABLE_DLL", true);
         }
 #endif
 

+ 1 - 1
Unity/Assets/Scripts/Editor/EntityTreeWindow/ContextMenu/MenuExample.cs

@@ -1,6 +1,6 @@
 namespace ET
 {
-#if !ENABLE_CODES
+#if !ENABLE_DLL
     [EntityMenu(typeof (Unit), "打开属性菜单")]
     public class UnitNumericWindowMenu: AEntityMenuHandler
     {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Unity.Hotfix.asmdef

@@ -16,7 +16,7 @@
     "precompiledReferences": [],
     "autoReferenced": true,
     "defineConstraints": [
-        "!ENABLE_CODES"
+        "!ENABLE_DLL"
     ],
     "versionDefines": [],
     "noEngineReferences": true

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Unity.HotfixView.asmdef

@@ -18,7 +18,7 @@
     "precompiledReferences": [],
     "autoReferenced": true,
     "defineConstraints": [
-        "!ENABLE_CODES"
+        "!ENABLE_DLL"
     ],
     "versionDefines": [],
     "noEngineReferences": false

+ 37 - 11
Unity/Assets/Scripts/Loader/CodeLoader.cs

@@ -13,7 +13,7 @@ namespace ET
 
 		public void Start()
 		{
-			if (!Define.EnableCodes)
+			if (!Define.EnableDll)
 			{
 				GlobalConfig globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
 				if (globalConfig.CodeMode != CodeMode.ClientServer)
@@ -40,12 +40,12 @@ namespace ET
 				if (!Define.IsEditor)
 				{
 					//Dictionary<string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
-					//assBytes = ((TextAsset)dictionary["Codes.dll"]).bytes;
-					//pdbBytes = ((TextAsset)dictionary["Codes.pdb"]).bytes;
+					//assBytes = ((TextAsset)dictionary["Model.dll"]).bytes;
+					//pdbBytes = ((TextAsset)dictionary["Model.pdb"]).bytes;
 					
-					// 这里为了方便做测试,直接加载了Unity/Temp/Bin/Debug/Codes.dll,真正打包要还原使用上面注释的代码
-					assBytes = File.ReadAllBytes(Path.Combine("../Unity", Define.BuildOutputDir, "Codes.dll"));
-					pdbBytes = File.ReadAllBytes(Path.Combine("../Unity", Define.BuildOutputDir, "Codes.pdb"));
+					// 这里为了方便做测试,直接加载了Unity/Temp/Bin/Debug/Model.dll,真正打包要还原使用上面注释的代码
+					assBytes = File.ReadAllBytes(Path.Combine("../Unity", Define.BuildOutputDir, "Model.dll"));
+					pdbBytes = File.ReadAllBytes(Path.Combine("../Unity", Define.BuildOutputDir, "Model.pdb"));
 
 					if (Define.EnableIL2CPP)
 					{
@@ -54,17 +54,43 @@ namespace ET
 				}
 				else
 				{
-					assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Codes.dll"));
-					pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Codes.pdb"));
+					assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Model.dll"));
+					pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Model.pdb"));
 				}
 			
 				this.assembly = Assembly.Load(assBytes, pdbBytes);
-
-				Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, typeof(Init).Assembly, this.assembly);
-				EventSystem.Instance.Add(types);
 			}
+			
+			this.LoadHotfix();
+			
 			IStaticMethod start = new StaticMethod(this.assembly, "ET.Entry", "Start");
 			start.Run();
 		}
+
+		public void LoadHotfix()
+		{
+			byte[] assBytes;
+			byte[] pdbBytes;
+			if (!Define.IsEditor)
+			{
+				//Dictionary<string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
+				//assBytes = ((TextAsset)dictionary["Hotfix.dll"]).bytes;
+				//pdbBytes = ((TextAsset)dictionary["Hotfix.pdb"]).bytes;
+					
+				// 这里为了方便做测试,直接加载了Unity/Temp/Bin/Debug/Hotfix.dll,真正打包要还原使用上面注释的代码
+				assBytes = File.ReadAllBytes(Path.Combine("../Unity", Define.BuildOutputDir, "Hotfix.dll"));
+				pdbBytes = File.ReadAllBytes(Path.Combine("../Unity", Define.BuildOutputDir, "Hotfix.pdb"));
+			}
+			else
+			{
+				assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Hotfix.dll"));
+				pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Hotfix.pdb"));
+			}
+			
+			Assembly hotfixAssembly = Assembly.Load(assBytes, pdbBytes);
+			
+			Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, typeof(Init).Assembly, this.assembly, hotfixAssembly);
+			EventSystem.Instance.Add(types);
+		}
 	}
 }

+ 3 - 3
Unity/Assets/Scripts/Loader/Define.cs

@@ -22,10 +22,10 @@
         public static bool IsEditor = false;
 #endif
 		
-#if ENABLE_CODES
-		public static bool EnableCodes = true;
+#if ENABLE_DLL
+		public static bool EnableDll = true;
 #else
-        public static bool EnableCodes = false;
+        public static bool EnableDll = false;
 #endif
 		
 #if ENABLE_VIEW

+ 1 - 1
Unity/Assets/Scripts/Model/Unity.Model.asmdef

@@ -14,7 +14,7 @@
     "precompiledReferences": [],
     "autoReferenced": true,
     "defineConstraints": [
-        "!ENABLE_CODES"
+        "!ENABLE_DLL"
     ],
     "versionDefines": [],
     "noEngineReferences": true

+ 1 - 1
Unity/Assets/Scripts/ModelView/Unity.ModelView.asmdef

@@ -15,7 +15,7 @@
     "precompiledReferences": [],
     "autoReferenced": true,
     "defineConstraints": [
-        "!ENABLE_CODES"
+        "!ENABLE_DLL"
     ],
     "versionDefines": [],
     "noEngineReferences": false

+ 1 - 1
Unity/Packages/manifest.json

@@ -1,7 +1,7 @@
 {
   "dependencies": {
+    "com.code-philosophy.hybridclr": "https://gitee.com/focus-creative-games/hybridclr_unity.git",
     "com.cysharp.memorypack": "https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack",
-    "com.focus-creative-games.hybridclr_unity": "https://gitee.com/focus-creative-games/hybridclr_unity.git",
     "com.unity.ide.rider": "3.0.21",
     "com.unity.ide.visualstudio": "2.0.17",
     "com.unity.ide.vscode": "1.2.5",

+ 6 - 6
Unity/Packages/packages-lock.json

@@ -1,18 +1,18 @@
 {
   "dependencies": {
-    "com.cysharp.memorypack": {
-      "version": "https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack",
+    "com.code-philosophy.hybridclr": {
+      "version": "https://gitee.com/focus-creative-games/hybridclr_unity.git",
       "depth": 0,
       "source": "git",
       "dependencies": {},
-      "hash": "09eb5f1535d0d01dee98c84fa110c21a436bd896"
+      "hash": "8e178c0e372a396e1bf1687e450d85693a95baf4"
     },
-    "com.focus-creative-games.hybridclr_unity": {
-      "version": "https://gitee.com/focus-creative-games/hybridclr_unity.git",
+    "com.cysharp.memorypack": {
+      "version": "https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack",
       "depth": 0,
       "source": "git",
       "dependencies": {},
-      "hash": "3702411ac82129c1683c788d5f695628ad9c1966"
+      "hash": "09eb5f1535d0d01dee98c84fa110c21a436bd896"
     },
     "com.unity.burst": {
       "version": "1.8.2",

+ 1 - 1
Unity/ProjectSettings/ProjectSettings.asset

@@ -842,7 +842,7 @@ PlayerSettings:
     Android: UNITY;SINGLE_THREAD
     Server: UNITY
     Standalone: UNITY;SINGLE_THREAD;ENABLE_VIEW;ENABLE_CODES
-    WebGL: UNITY
+    WebGL: UNITY;ENABLE_CODES;ENABLE_DLL
     iPhone: UNITY;SINGLE_THREAD;ENABLE_CODES
   additionalCompilerArguments: {}
   platformArchitecture: