Przeglądaj źródła

1. 客户端改成动态加载Code.dll的方式加载代码,方便后面接入ILRuntime,运行Tools->BuildDll即可编译代码
2. 4个代码工程asmdef都已经改成Editor模式,不BuildDll将无法运行项目
3. 后面将实现热重载功能,也就是将两个Hotfix dll单独编译,运行期间可以动态加载,不用重启客户端

tanghai 4 lat temu
rodzic
commit
e5fa8e6aea
29 zmienionych plików z 414 dodań i 357 usunięć
  1. 12 11
      Book/1.1运行指南.md
  2. 1 1
      Unity/Assets/Bundles/Code.meta
  3. 31 16
      Unity/Assets/Editor/BuildEditor/BuildAssemblieEditor.cs
  4. 3 2
      Unity/Assets/Hotfix/Unity.Hotfix.asmdef
  5. 3 2
      Unity/Assets/HotfixView/Unity.HotfixView.asmdef
  6. 3 2
      Unity/Assets/Model/Unity.Model.asmdef
  7. 7 31
      Unity/Assets/ModelView/Demo/Entry.cs
  8. 6 5
      Unity/Assets/ModelView/Unity.ModelView.asmdef
  9. 56 0
      Unity/Assets/Mono/Helper/AssetsBundleHelper.cs
  10. 1 1
      Unity/Assets/Mono/Helper/AssetsBundleHelper.cs.meta
  11. 66 0
      Unity/Assets/Mono/Helper/CodeLoader.cs
  12. 1 1
      Unity/Assets/Mono/Helper/CodeLoader.cs.meta
  13. 10 0
      Unity/Assets/Mono/Helper/DllHelper.cs
  14. 1 1
      Unity/Assets/Mono/Helper/DllHelper.cs.meta
  15. 56 0
      Unity/Assets/Mono/Helper/ILHelper.cs
  16. 11 0
      Unity/Assets/Mono/Helper/ILHelper.cs.meta
  17. 47 0
      Unity/Assets/Mono/Helper/ILStaticMethod.cs
  18. 11 0
      Unity/Assets/Mono/Helper/ILStaticMethod.cs.meta
  19. 10 0
      Unity/Assets/Mono/Helper/IStaticMethod.cs
  20. 11 0
      Unity/Assets/Mono/Helper/IStaticMethod.cs.meta
  21. 0 84
      Unity/Assets/Mono/Helper/LoadHelper.cs
  22. 45 0
      Unity/Assets/Mono/Helper/MonoStaticMethod.cs
  23. 11 0
      Unity/Assets/Mono/Helper/MonoStaticMethod.cs.meta
  24. 0 117
      Unity/Assets/Mono/Helper/StreamHelper.cs
  25. 0 8
      Unity/Assets/Mono/Interpreter.meta
  26. 0 40
      Unity/Assets/Mono/Interpreter/Interpreter.cs
  27. 7 33
      Unity/Assets/Mono/MonoBehaviour/Init.cs
  28. 2 2
      Unity/Assets/Mono/Unity.Mono.asmdef
  29. 2 0
      Unity/Unity.sln.DotSettings

+ 12 - 11
Book/1.1运行指南.md

@@ -1,23 +1,24 @@
 # 运行步骤  
-1. visual studio必须使用vs2019(更新到最新版), VS2019需要勾选安装以下内容:
+1. visual studio必须使用vs2022(更新到最新版), VS2022需要勾选安装以下内容:
    - .net 桌面开发  
-   - 去net core官网下载安装 .net5 
+   -  安装 .net6  
 
-2. master分支需要unity2020.3版(用到了C#8的语法)
+2. master分支需要unity2020.4版(用到了C#8的语法)  
 
-3. 启动Unity, 菜单 File -> Open Project... -> Open 选中ET/Unity文件夹,点击选择文件夹按钮。
+3. 启动Unity, 菜单 File -> Open Project... -> Open 选中ET/Unity文件夹,点击选择文件夹按钮。  
 
-4. 点击Unity菜单 Assets -> Open C# Project 启动vs编译
+4. 点击Unity菜单 Assets -> Open C# Project 启动vs  
 
-5. 用vs2019打开 ET/Client-Server.sln 编译(**一定要全部工程编译,右键VS解决方案,全部编译**)
+5. 运行Unity菜单上的 Tools->BuildDll,这一步将编译客户端代码  
 
-6. 导表工具,编译完成后命令行进入 Bin 目录,执行 dotnet Server.dll --AppType=ExcelExporter  
+6. 用vs2022打开 ET/Client-Server.sln 编译(**一定要全部工程编译,右键VS解决方案,全部编译**)
 
-7. 导出协议工具,编译完成后进入 Bin 目录,执行 dotnet Server.dll --AppType=Proto2CS  
-# 测试状态同步demo
+7. 导表工具,编译完成后命令行进入 Bin 目录,执行 dotnet Server.dll --AppType=ExcelExporter  
 
->  帧同步demo已经删除,需要的话请看ET4.0分支
+8. 导出协议工具,编译完成后进入 Bin 目录,执行 dotnet Server.dll --AppType=Proto2CS  
 
+9. Unity中双击Scenes目录中的Init场景,点击Play即可运行
+# 测试状态同步demo
 1. 想修改配置就进入 Excel 目录修改对应的表格,做运行步骤的第6步,然后重新运行 Server.App工程来启动服务端。
 
 2. Unity->tools菜单->打包工具,选择PC,勾选是否打包exe,点击开始打包,打出一个PC包在Release目录下
@@ -34,7 +35,7 @@
 
 1. 中文目录。  
 2. vs没有安装vs相关组件
-3. 没安装 .net5
+3. 没安装 .net6
 4. 没编译服务端所有工程
 5. VS要更新到最新版本  
 6. Unity版本太低

+ 1 - 1
Unity/Assets/Bundles/Code.meta

@@ -4,5 +4,5 @@ folderAsset: yes
 DefaultImporter:
   externalObjects: {}
   userData: 
-  assetBundleName: 
+  assetBundleName: code.unity3d
   assetBundleVariant: 

+ 31 - 16
Unity/Assets/Editor/BuildEditor/BuildAssemblieEditor.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Threading.Tasks;
 using UnityEngine;
 using UnityEditor;
 using UnityEditor.Compilation;
@@ -11,7 +12,7 @@ namespace ET
     public static class BuildAssemblieEditor
     {
         private const string ScriptAssembliesDir = "Temp/MyAssembly/";
-        private const string CodeDir = "Assets/Res/Code/";
+        private const string CodeDir = "Assets/Bundles/Code/";
 
         [MenuItem("Tools/BuildDll")]
         public static void BuildDll()
@@ -26,13 +27,6 @@ namespace ET
             AssetDatabase.Refresh();
         }
 
-        private static void CopyDllAndPdb(string FileName)
-        {
-            Debug.Log("复制Code.dll到Bundles/Code目录");
-            Directory.CreateDirectory(CodeDir);
-            File.Copy(Path.Combine(ScriptAssembliesDir, FileName + ".dll"), Path.Combine(CodeDir, FileName + ".dll.bytes"), true);
-            File.Copy(Path.Combine(ScriptAssembliesDir, FileName + ".pdb"), Path.Combine(CodeDir, FileName + ".pdb.bytes"), true);
-        }
 
         private static void BuildMuteAssembly(string Name, string[] CodeDirectorys)
         {
@@ -87,14 +81,13 @@ namespace ET
                 "Library/ScriptAssemblies/Unity.HotfixView.dll"
             };
 
-            assemblyBuilder.buildStarted += delegate(string assemblyPath) { Debug.LogFormat("程序集开始构建:" + assemblyPath); };
+            assemblyBuilder.buildStarted += delegate(string assemblyPath) { Debug.LogFormat("build start:" + assemblyPath); };
 
             assemblyBuilder.buildFinished += delegate(string assemblyPath, CompilerMessage[] compilerMessages)
             {
                 int errorCount = compilerMessages.Count(m => m.type == CompilerMessageType.Error);
                 int warningCount = compilerMessages.Count(m => m.type == CompilerMessageType.Warning);
 
-                Debug.LogFormat("程序集构建完成:" + assemblyPath);
                 Debug.LogFormat("Warnings: {0} - Errors: {1}", warningCount, errorCount);
 
                 if (warningCount > 0)
@@ -111,18 +104,40 @@ namespace ET
                             Debug.LogError(compilerMessages[i].message);
                         }
                     }
-
-                    return;
                 }
-                
-                CopyDllAndPdb(Name);
             };
-
+            
             //开始构建
             if (!assemblyBuilder.Build())
             {
-                Debug.LogErrorFormat("构建程序集失败:" + assemblyBuilder.assemblyPath);
+                Debug.LogErrorFormat("build fail:" + assemblyBuilder.assemblyPath);
+                return;
             }
+            
+            AfterCompiling(assemblyBuilder).Coroutine();
+        }
+
+        private static async ETVoid AfterCompiling(AssemblyBuilder assemblyBuilder)
+        {
+            while (EditorApplication.isCompiling)
+            {
+                await Task.Delay(100);
+            }
+            
+            Debug.Log("copy Code.dll to Bundles/Code");
+            Directory.CreateDirectory(CodeDir);
+            File.Copy(Path.Combine(ScriptAssembliesDir, "Code.dll"), Path.Combine(CodeDir, "Code.dll.bytes"), true);
+            File.Copy(Path.Combine(ScriptAssembliesDir, "Code.pdb"), Path.Combine(CodeDir, "Code.pdb.bytes"), true);
+            AssetDatabase.Refresh();
+            
+            // 设置ab包
+            AssetImporter assetImporter1 = AssetImporter.GetAtPath("Assets/Bundles/Code/Code.dll.bytes");
+            assetImporter1.assetBundleName = "Code.unity3d";
+            AssetImporter assetImporter2 = AssetImporter.GetAtPath("Assets/Bundles/Code/Code.pdb.bytes");
+            assetImporter2.assetBundleName = "Code.unity3d";
+            
+            AssetDatabase.Refresh();
+            Debug.Log("build success!");
         }
     }
 }

+ 3 - 2
Unity/Assets/Hotfix/Unity.Hotfix.asmdef

@@ -1,12 +1,13 @@
 {
     "name": "Unity.Hotfix",
-    "rootNamespace": "ET",
     "references": [
         "Unity.Model",
         "Unity.ThirdParty",
         "Unity.Mono"
     ],
-    "includePlatforms": [],
+    "includePlatforms": [
+        "Editor"
+    ],
     "excludePlatforms": [],
     "allowUnsafeCode": true,
     "overrideReferences": false,

+ 3 - 2
Unity/Assets/HotfixView/Unity.HotfixView.asmdef

@@ -1,6 +1,5 @@
 {
     "name": "Unity.HotfixView",
-    "rootNamespace": "ET",
     "references": [
         "GUID:703e1d0810996ed4b9064f1041de8bdc",
         "GUID:997f003cfffd9ec4fae70c0ac9b0ec2b",
@@ -8,7 +7,9 @@
         "GUID:bebd02018e98e44409a761968a7cbcd9",
         "GUID:6e17cd4649ea94c0cb18f30a60b9b4b4"
     ],
-    "includePlatforms": [],
+    "includePlatforms": [
+        "Editor"
+    ],
     "excludePlatforms": [],
     "allowUnsafeCode": false,
     "overrideReferences": false,

+ 3 - 2
Unity/Assets/Model/Unity.Model.asmdef

@@ -1,11 +1,12 @@
 {
     "name": "Unity.Model",
-    "rootNamespace": "ET",
     "references": [
         "Unity.ThirdParty",
         "Unity.Mono"
     ],
-    "includePlatforms": [],
+    "includePlatforms": [
+        "Editor"
+    ],
     "excludePlatforms": [],
     "allowUnsafeCode": true,
     "overrideReferences": false,

+ 7 - 31
Unity/Assets/ModelView/Demo/Entry.cs

@@ -1,26 +1,18 @@
 using System;
-using System.Linq;
-using System.Reflection;
 
 namespace ET
 {
-	public class MonoEntry : IEntry
+	public static class Entry
 	{
-		public void Start()
+		public static void Start()
 		{
 			try
 			{
-				string[] assemblyNames = { "Unity.Model.dll", "Unity.Hotfix.dll", "Unity.ModelView.dll", "Unity.HotfixView.dll" };
-				
-				foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
-				{
-					string assemblyName = $"{assembly.GetName().Name}.dll";
-					if (!assemblyNames.Contains(assemblyName))
-					{
-						continue;
-					}
-					Game.EventSystem.Add(assembly);
-				}
+				Game.EventSystem.Add(typeof(Entry).Assembly);
+
+				CodeLoader.Instance.Update = Game.Update;
+				CodeLoader.Instance.LateUpdate = Game.LateUpdate;
+				CodeLoader.Instance.OnApplicationQuit = Game.Close;
 				
 				ProtobufHelper.Init();
 				
@@ -33,21 +25,5 @@ namespace ET
 				Log.Error(e);
 			}
 		}
-
-		public void Update()
-		{
-			ThreadSynchronizationContext.Instance.Update();
-			Game.EventSystem.Update();
-		}
-
-		public void LateUpdate()
-		{
-			Game.EventSystem.LateUpdate();
-		}
-
-		public void OnApplicationQuit()
-		{
-			Game.Close();
-		}
 	}
 }

+ 6 - 5
Unity/Assets/ModelView/Unity.ModelView.asmdef

@@ -1,12 +1,13 @@
 {
     "name": "Unity.ModelView",
-    "rootNamespace": "ET",
     "references": [
-        "GUID:997f003cfffd9ec4fae70c0ac9b0ec2b",
-        "GUID:bebd02018e98e44409a761968a7cbcd9",
-        "GUID:6e17cd4649ea94c0cb18f30a60b9b4b4"
+        "Unity.Model",
+        "Unity.ThirdParty",
+        "Unity.Mono"
+    ],
+    "includePlatforms": [
+        "Editor"
     ],
-    "includePlatforms": [],
     "excludePlatforms": [],
     "allowUnsafeCode": false,
     "overrideReferences": false,

+ 56 - 0
Unity/Assets/Mono/Helper/AssetsBundleHelper.cs

@@ -0,0 +1,56 @@
+using System.Collections.Generic;
+using System.IO;
+
+namespace ET
+{
+    public static class AssetsBundleHelper
+    {
+        public static Dictionary<string, UnityEngine.Object> LoadBundle(string assetBundleName)
+        {
+            assetBundleName = assetBundleName.ToLower();
+
+            Dictionary<string, UnityEngine.Object> objects = new Dictionary<string, UnityEngine.Object>();
+            if (!Define.IsAsync)
+            {
+                if (Define.IsEditor)
+                {
+                    string[] realPath = null;
+                    realPath = Define.GetAssetPathsFromAssetBundle(assetBundleName);
+                    foreach (string s in realPath)
+                    {
+                        //string assetName = Path.GetFileNameWithoutExtension(s);
+                        UnityEngine.Object resource = Define.LoadAssetAtPath(s);
+                        objects.Add(resource.name, resource);
+                    }
+                }
+                return objects;
+            }
+
+            string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
+            UnityEngine.AssetBundle assetBundle = null;
+            if (File.Exists(p))
+            {
+                assetBundle = UnityEngine.AssetBundle.LoadFromFile(p);
+            }
+            else
+            {
+                p = Path.Combine(PathHelper.AppResPath, assetBundleName);
+                assetBundle = UnityEngine.AssetBundle.LoadFromFile(p);
+            }
+
+            if (assetBundle == null)
+            {
+                // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功
+                UnityEngine.Debug.LogWarning($"assets bundle not found: {assetBundleName}");
+                return objects;
+            }
+
+            UnityEngine.Object[] assets = assetBundle.LoadAllAssets();
+            foreach (UnityEngine.Object asset in assets)
+            {
+                objects.Add(asset.name, asset);
+            }
+            return objects;
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Mono/Helper/LoadHelper.cs.meta → Unity/Assets/Mono/Helper/AssetsBundleHelper.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 61ea67c04548d654ea92faa72a6dbc0b
+guid: 59177274cf204f04cb378cf66aa62218
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 66 - 0
Unity/Assets/Mono/Helper/CodeLoader.cs

@@ -0,0 +1,66 @@
+#define ILRuntime1
+
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+#if ILRuntime
+using System.Linq;
+#endif
+
+namespace ET
+{
+	public class CodeLoader
+	{
+		public static CodeLoader Instance = new CodeLoader();
+		
+		public Action Update { get; set; }
+		public Action LateUpdate { get; set; }
+		public Action OnApplicationQuit { get; set; }
+
+		private readonly IStaticMethod start;
+		
+		private readonly Type[] hotfixTypes;
+
+		private CodeLoader()
+		{
+			Dictionary<string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
+			byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
+			byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;
+			
+#if ILRuntime
+			ILRuntime.Runtime.Enviorment.AppDomain appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
+			using (System.IO.MemoryStream assStream = new System.IO.MemoryStream(assBytes))
+			using (System.IO.MemoryStream pdbStream = new System.IO.MemoryStream(pdbBytes))
+			{
+				appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
+			}
+			ILHelper.InitILRuntime(appDomain);
+			
+			this.hotfixTypes = Type.EmptyTypes;
+			this.hotfixTypes = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
+#else
+
+			System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(assBytes, pdbBytes);
+			hotfixTypes = assembly.GetTypes();
+#endif
+			
+
+#if ILRuntime
+			this.start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0);
+#else
+			this.start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
+#endif
+		}
+		
+		public void Start()
+		{
+			this.start.Run();
+		}
+
+		public Type[] GetHotfixTypes()
+		{
+			return this.hotfixTypes;
+		}
+	}
+}

+ 1 - 1
Unity/Assets/Mono/Interpreter/Interpreter.cs.meta → Unity/Assets/Mono/Helper/CodeLoader.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 4964880e9c338254aabc8829c3ad71e6
+guid: f552377e6dfa5ac4da1f2430f31664eb
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 10 - 0
Unity/Assets/Mono/Helper/DllHelper.cs

@@ -0,0 +1,10 @@
+namespace ET
+{
+    public static class DllHelper
+    {
+        public static void GetHotfixAssembly()
+        {
+            
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Mono/Helper/StreamHelper.cs.meta → Unity/Assets/Mono/Helper/DllHelper.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 491a44ce59af0a848aff89ab42ec4842
+guid: 42cae7cf9d71fa74a99dbd6e30692202
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 56 - 0
Unity/Assets/Mono/Helper/ILHelper.cs

@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using ILRuntime.CLR.Method;
+using ILRuntime.CLR.TypeSystem;
+using ILRuntime.Runtime.Enviorment;
+using ILRuntime.Runtime.Intepreter;
+using UnityEngine;
+
+namespace ET
+{
+    public static class ILHelper
+    {
+        public static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
+        {
+            /*
+            // 注册重定向函数
+
+            // 注册委托
+            appdomain.DelegateManager.RegisterMethodDelegate<List<object>>();
+            appdomain.DelegateManager.RegisterMethodDelegate<AChannel, System.Net.Sockets.SocketError>();
+            appdomain.DelegateManager.RegisterMethodDelegate<byte[], int, int>();
+            appdomain.DelegateManager.RegisterMethodDelegate<IResponse>();
+            appdomain.DelegateManager.RegisterMethodDelegate<Session, object>();
+            appdomain.DelegateManager.RegisterMethodDelegate<Session, ushort, MemoryStream>();
+            appdomain.DelegateManager.RegisterMethodDelegate<Session>();
+            appdomain.DelegateManager.RegisterMethodDelegate<ILTypeInstance>();
+            appdomain.DelegateManager.RegisterFunctionDelegate<Google.Protobuf.Adapt_IMessage.Adaptor>();
+            appdomain.DelegateManager.RegisterMethodDelegate<Google.Protobuf.Adapt_IMessage.Adaptor>();
+
+            CLRBindings.Initialize(appdomain);
+
+            // 注册适配器
+            Assembly assembly = typeof(Init).Assembly;
+            foreach (Type type in assembly.GetTypes())
+            {
+                object[] attrs = type.GetCustomAttributes(typeof(ILAdapterAttribute), false);
+                if (attrs.Length == 0)
+                {
+                    continue;
+                }
+                object obj = Activator.CreateInstance(type);
+                CrossBindingAdaptor adaptor = obj as CrossBindingAdaptor;
+                if (adaptor == null)
+                {
+                    continue;
+                }
+                appdomain.RegisterCrossBindingAdaptor(adaptor);
+            }
+
+            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
+            */
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Mono/Helper/ILHelper.cs.meta

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

+ 47 - 0
Unity/Assets/Mono/Helper/ILStaticMethod.cs

@@ -0,0 +1,47 @@
+using ILRuntime.CLR.Method;
+using UnityEngine;
+
+namespace ET
+{
+    public class ILStaticMethod : IStaticMethod
+    {
+        private readonly ILRuntime.Runtime.Enviorment.AppDomain appDomain;
+        private readonly IMethod method;
+        private readonly object[] param;
+
+        public ILStaticMethod(ILRuntime.Runtime.Enviorment.AppDomain appDomain, string typeName, string methodName, int paramsCount)
+        {
+            this.appDomain = appDomain;
+            this.method = appDomain.GetType(typeName).GetMethod(methodName, paramsCount);
+            this.param = new object[paramsCount];
+        }
+
+        public override void Run()
+        {
+            this.appDomain.Invoke(this.method, null, this.param);
+        }
+
+        public override void Run(object a)
+        {
+            this.param[0] = a;
+            this.appDomain.Invoke(this.method, null, param);
+        }
+
+        public override void Run(object a, object b)
+        {
+            this.param[0] = a;
+            this.param[1] = b;
+            this.appDomain.Invoke(this.method, null, param);
+        }
+
+        public override void Run(object a, object b, object c)
+        {
+            this.param[0] = a;
+            this.param[1] = b;
+            this.param[2] = c;
+            this.appDomain.Invoke(this.method, null, param);
+        }
+    }
+}
+
+

+ 11 - 0
Unity/Assets/Mono/Helper/ILStaticMethod.cs.meta

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

+ 10 - 0
Unity/Assets/Mono/Helper/IStaticMethod.cs

@@ -0,0 +1,10 @@
+namespace ET
+{
+    public abstract class IStaticMethod
+    {
+        public abstract void Run();
+        public abstract void Run(object a);
+        public abstract void Run(object a, object b);
+        public abstract void Run(object a, object b, object c);
+    }
+}

+ 11 - 0
Unity/Assets/Mono/Helper/IStaticMethod.cs.meta

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

+ 0 - 84
Unity/Assets/Mono/Helper/LoadHelper.cs

@@ -1,84 +0,0 @@
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using UnityEditor;
-using UnityEngine;
-
-namespace ET
-{
-    public static class LoadHelper
-    {
-        public static TextAsset LoadTextAsset(string path) 
-        {
-            if (Application.isEditor)
-            {
-                TextAsset resource = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path) as TextAsset;
-                return resource ;
-            }
-
-            path = path + ".unity3d";
-            string p = Path.Combine(PathHelper.AppHotfixResPath, path);
-            AssetBundle assetBundle = null;
-            if (File.Exists(p))
-            {
-                assetBundle = AssetBundle.LoadFromFile(p);
-            }
-            else
-            {
-                p = Path.Combine(PathHelper.AppResPath, path);
-                assetBundle = AssetBundle.LoadFromFile(p);
-            }
-
-            if (assetBundle == null)
-            {
-                // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功
-                Debug.LogError($"assets bundle not found: {path}");
-                return default(TextAsset);
-            }
-            return assetBundle.LoadAsset(path)  as  TextAsset;
-        }
-
-
-        public static UnityEngine.Object LoadAssetAtPath(string assetPath)
-        {
-            return AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
-        }
-
-        public static  int GetAssetPathsFromAssetBundleCount(string assetBundleName)
-        {
-            string[] resultArr =  AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
-            return resultArr.Length;
-        }
-        
-        public static  string[] GetAssetPathsFromAssetBundle(string assetBundleName)
-        {
-            return AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
-        }
-        
-        
-        public static int GetAssetBundleDependenciesCount(string assetBundleName, bool recursive)
-        {
-            string[] result =  AssetDatabase.GetAssetBundleDependencies(assetBundleName, recursive);
-            return result.Length;
-        }
-        
-
-        public static  string[] GetAssetBundleDependencies(string assetBundleName, bool recursive)
-        {
-            return  AssetDatabase.GetAssetBundleDependencies(assetBundleName, recursive);
-        }
-
-
-        public static int GetanimationClipsLength(this Animator self )
-        {
-            return self.runtimeAnimatorController.animationClips.Length;
-        }
-
-        public static int GetAnimatorControllerParameterLength(this Animator self )
-        {
-            return self.parameters.Length;
-        }
-
-
-    }
-}

+ 45 - 0
Unity/Assets/Mono/Helper/MonoStaticMethod.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Reflection;
+
+namespace ET
+{
+    public class MonoStaticMethod : IStaticMethod
+    {
+        private readonly MethodInfo methodInfo;
+
+        private readonly object[] param;
+
+        public MonoStaticMethod(Assembly assembly, string typeName, string methodName)
+        {
+            this.methodInfo = assembly.GetType(typeName).GetMethod(methodName);
+            this.param = new object[this.methodInfo.GetParameters().Length];
+        }
+
+        public override void Run()
+        {
+            this.methodInfo.Invoke(null, param);
+        }
+
+        public override void Run(object a)
+        {
+            this.param[0] = a;
+            this.methodInfo.Invoke(null, param);
+        }
+
+        public override void Run(object a, object b)
+        {
+            this.param[0] = a;
+            this.param[1] = b;
+            this.methodInfo.Invoke(null, param);
+        }
+
+        public override void Run(object a, object b, object c)
+        {
+            this.param[0] = a;
+            this.param[1] = b;
+            this.param[2] = c;
+            this.methodInfo.Invoke(null, param);
+        }
+    }
+}
+

+ 11 - 0
Unity/Assets/Mono/Helper/MonoStaticMethod.cs.meta

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

+ 0 - 117
Unity/Assets/Mono/Helper/StreamHelper.cs

@@ -1,117 +0,0 @@
-using System;
-using System.IO;
-
-namespace ET
-{
-	public static class StreamHelper
-	{
-		public static void WriteToUint(this Stream stream, int offset, uint num)
-		{
-			if(stream == null)
-			{
-				return;
-			}
-
-			stream.Seek(offset, SeekOrigin.Begin);
-			stream.WriteByte((byte)(num & 0xff));
-			stream.WriteByte((byte)((num & 0xff00) >> 8));
-			stream.WriteByte((byte)((num & 0xff0000) >> 16));
-			stream.WriteByte((byte)((num & 0xff000000) >> 24));
-		}
-		
-		public static void WriteToInt(this Stream stream, int offset, int num)
-		{
-			if (stream == null)
-			{
-				return;
-			}
-
-			stream.Seek(offset, SeekOrigin.Begin);
-			stream.WriteByte((byte)(num & 0xff));
-			stream.WriteByte((byte)((num & 0xff00) >> 8));
-			stream.WriteByte((byte)((num & 0xff0000) >> 16));
-			stream.WriteByte((byte)((num & 0xff000000) >> 24));
-		}
-		
-		public static void WriteToByte(this Stream stream, int offset, byte num)
-		{
-			if (stream == null)
-			{
-				return;
-			}
-
-			stream.Seek(offset, SeekOrigin.Begin);
-			stream.WriteByte(num);
-		}
-		
-		public static void WriteToShort(this Stream stream, int offset, short num)
-		{
-			if (stream == null)
-			{
-				return;
-			}
-
-			stream.Seek(offset, SeekOrigin.Begin);
-			stream.WriteByte((byte)(num & 0xff));
-			stream.WriteByte((byte)((num & 0xff00) >> 8));
-		}
-		
-		public static void WriteToUshort(this Stream stream, int offset, ushort num)
-		{
-			if (stream == null)
-			{
-				return;
-			}
-
-			stream.Seek(offset, SeekOrigin.Begin);
-			stream.WriteByte((byte)(num & 0xff));
-			stream.WriteByte((byte)((num & 0xff00) >> 8));
-		}
-
-		public static int ToInt32(this MemoryStream memoryStream, int offset)
-		{
-			if (memoryStream == null)
-			{
-				return 0;
-			}
-
-			return BitConverter.ToInt32(memoryStream.GetBuffer(), offset);
-		}
-
-		public static ushort ToUInt16(this MemoryStream memoryStream, int offset)
-		{
-			if (memoryStream == null)
-			{
-				return 0;
-			}
-
-			return BitConverter.ToUInt16(memoryStream.GetBuffer(), offset);
-		}
-
-		public static byte[] ReadBytes(MemoryStream memoryStream, int offset)
-		{
-			if (memoryStream != null && offset >= 0)
-			{
-				var count = memoryStream.Length - offset;
-
-				if (count > 0)
-				{
-					var bytes = new byte[count];
-					memoryStream.Read(bytes, 0, bytes.Length);
-
-					return bytes;
-				}
-			}
-
-			return null;
-		}
-
-		public static void WriteBytes(MemoryStream memoryStream, byte[] bytes)
-		{
-			if (memoryStream != null && bytes != null)
-			{
-				memoryStream.Write(bytes, 0, bytes.Length);
-			}
-		}
-	}
-}

+ 0 - 8
Unity/Assets/Mono/Interpreter.meta

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

+ 0 - 40
Unity/Assets/Mono/Interpreter/Interpreter.cs

@@ -1,40 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace ET
-{
-    public static class Interpreter
-    {
-        private const string InterpreterDll = "Interpreter";
-        
-        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        public delegate void LogCallback(IntPtr buf, int len);
-        
-        private static LogCallback logCallback;
-        
-        [DllImport(InterpreterDll, CallingConvention = CallingConvention.Cdecl)]
-        private static extern void interpreter_set_log(LogCallback logCallback);
-        
-        [DllImport(InterpreterDll, CallingConvention = CallingConvention.Cdecl)]
-        private static extern void interpreter_log([In][MarshalAs(UnmanagedType.LPStr)] string str);
-        
-        [DllImport(InterpreterDll, CallingConvention = CallingConvention.Cdecl)]
-        private static extern void interpreter_init([In][MarshalAs(UnmanagedType.LPStr)] string reloadDir, [In][MarshalAs(UnmanagedType.LPStr)] string exeName);
-
-        public static void InterpreterSetLog(LogCallback plog)
-        {
-            logCallback = plog;
-            interpreter_set_log(logCallback);
-        }
-        
-        public static void InterpreterLog(string str)
-        {
-            interpreter_log(str);
-        }
-
-        public static void InterpreterInit([In][MarshalAs(UnmanagedType.LPStr)]string reloadDir, [In][MarshalAs(UnmanagedType.LPStr)]string exeName)
-        {
-            interpreter_init(reloadDir, exeName);
-        }
-    }
-}

+ 7 - 33
Unity/Assets/Mono/MonoBehaviour/Init.cs

@@ -1,21 +1,11 @@
-using System;
-using System.Reflection;
-using System.Threading;
+using System.Threading;
 using UnityEngine;
 
 namespace ET
 {
-	public interface IEntry
-	{
-		void Start();
-		void Update();
-		void LateUpdate();
-		void OnApplicationQuit();
-	}
-	
 	public class Init: MonoBehaviour
 	{
-		private IEntry entry;
+		private CodeLoader codeLoader;
 		
 		private void Awake()
 		{
@@ -23,43 +13,27 @@ namespace ET
 			
 			DontDestroyOnLoad(gameObject);
 
-			Assembly modelAssembly = null;
-
-			UnityEngine.Debug.Log("unity editor mode!");
-			foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
-			{
-				string assemblyName = $"{assembly.GetName().Name}.dll";
-				if (assemblyName != "Unity.ModelView.dll")
-				{
-					continue;
-				}
-
-				modelAssembly = assembly;
-				break;
-			}
-
-			Type initType = modelAssembly.GetType("ET.MonoEntry");
-			this.entry = Activator.CreateInstance(initType) as IEntry;
+			this.codeLoader = CodeLoader.Instance;
 		}
 
 		private void Start()
 		{
-			this.entry.Start();
+			this.codeLoader.Start();
 		}
 
 		private void Update()
 		{
-			this.entry.Update();
+			this.codeLoader.Update();
 		}
 
 		private void LateUpdate()
 		{
-			this.entry.LateUpdate();
+			this.codeLoader.LateUpdate();
 		}
 
 		private void OnApplicationQuit()
 		{
-			this.entry.OnApplicationQuit();
+			this.codeLoader.OnApplicationQuit();
 		}
 	}
 }

+ 2 - 2
Unity/Assets/Mono/Unity.Mono.asmdef

@@ -1,8 +1,8 @@
 {
     "name": "Unity.Mono",
-    "rootNamespace": "ET",
     "references": [
-        "GUID:bebd02018e98e44409a761968a7cbcd9"
+        "GUID:bebd02018e98e44409a761968a7cbcd9",
+        "GUID:7a1fa966b0ea23f40a6a4dc4dab1e297"
     ],
     "includePlatforms": [],
     "excludePlatforms": [],

+ 2 - 0
Unity/Unity.sln.DotSettings

@@ -412,6 +412,7 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
 	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsParsFormattingSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EXml_002ECodeStyle_002EFormatSettingsUpgrade_002EXmlMoveToCommonFormatterSettingsUpgrade/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002ERider_002EBackend_002EFeatures_002EDebugger_002ESettings_002EMigration_002ERiderSymbolServersSettingsUpgrade/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/Environment/TextControl/HighlightCurrentLine/@EntryValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/Environment/UnitTesting/MsTestProvider/UseTestRunConfigFromMetadataFile/@EntryValue">False</s:Boolean>
 	<s:Boolean x:Key="/Default/Environment/UpdatesManger/IsDownloadUpdateDataAllowed/@EntryValue">False</s:Boolean>
@@ -994,6 +995,7 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
 	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Subtract/@KeyIndexDefined">True</s:Boolean>
 	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Tab/@KeyIndexDefined">True</s:Boolean>
 	<s:Boolean x:Key="/Default/Housekeeping/VsActionManager/KeyboardShortcutToVsCommand/=Up/@KeyIndexDefined">True</s:Boolean>
+	<s:Boolean x:Key="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue">False</s:Boolean>
 	<s:String x:Key="/Default/SnapshotsStore/CurrentStore/@EntryValue">C:\Users\USER-PC\AppData\Local\JetBrains\Shared\vAny\Sessions</s:String>
 	<s:Boolean x:Key="/Default/SymbolServers/RestoreDecompileSetting/@EntryValue">False</s:Boolean>
 	<s:Double x:Key="/Default/TimelineLayout/MethodsPanelHeight/@EntryValue">366</s:Double></wpf:ResourceDictionary>