void LoadHotFixAssembly() { appdomain = new AppDomain(); pdb = null; //编译模式 if (!Assets.runtimeMode) { if (File.Exists(dllPath)) { fs = new MemoryStream(DLLMgr.FileToByte(dllPath)); } else { Log.PrintError("DLL文件不存在"); return; } //查看是否有PDB文件 if (File.Exists(pdbPath) && UsePdb && (File.GetLastWriteTime(dllPath) - File.GetLastWriteTime(pdbPath)).Seconds < 30) { pdb = new MemoryStream(DLLMgr.FileToByte(pdbPath)); } } else//解密加载 { var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset)); if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; try { var original = CryptoHelper.AesDecrypt(dll.bytes, Key); fs = new MemoryStream(original); } catch (Exception ex) { Log.PrintError("加载热更DLL失败,可能是解密密码不正确"); Log.PrintError("加载热更DLL错误:\n" + ex.Message); return; } } try { appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider()); } catch (Exception e) { if (!UsePdb) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); Log.PrintError("加载热更DLL错误:\n" + e.Message); return; } Log.PrintError("PDB不可用,可能是DLL和PDB版本不一致,可能DLL是Release,如果是Release出包,请取消UsePdb选项,本次已跳过使用PDB"); UsePdb = false; LoadHotFixAssembly(); } InitILrt.InitializeILRuntime(appdomain); OnHotFixLoaded(); }
void LoadHotFixAssembly() { Appdomain = new AppDomain(); _pdb = null; byte[] buffer; //开发模式 #if XASSET_PRO if (Assets.development) #else if (!Assets.runtimeMode) #endif { if (File.Exists(DLLPath))//直接读DLL { buffer = DLLMgr.FileToByte(DLLPath); //模拟加密 buffer = CryptoHelper.AesEncrypt(buffer, key); } else { Log.PrintError("DLL文件不存在"); return; } //查看是否有PDB文件 if (File.Exists(PdbPath) && usePdb && (File.GetLastWriteTime(DLLPath) - File.GetLastWriteTime(PdbPath)).Seconds < 30) { _pdb = new MemoryStream(DLLMgr.FileToByte(PdbPath)); } } else//真机模式解密加载 { var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset)); if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; buffer = new byte[dll.bytes.Length]; Array.Copy(dll.bytes, buffer, dll.bytes.Length); dllAsset.Release();//释放掉不需要再用的dll } try { // var original = CryptoHelper.AesDecrypt(dll.bytes, Key);以前的用法,过时了 _fs = new JStream(buffer, key); /* * 如果一定要先解密,可以这样: * var original = CryptoHelper.AesDecrypt(dll.bytes, Key); * fs = new JStream(original, Key); * fs.Encrypted = false; */ Appdomain.LoadAssembly(_fs, _pdb, new PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL错误:\n" + e); if (!usePdb) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); } else { Log.PrintError("PDB不可用,可能是DLL和PDB版本不一致,可能DLL是Release,如果是Release出包,请取消UsePdb选项,本次已跳过使用PDB"); usePdb = false; LoadHotFixAssembly(); } return; } Success = true; InitILrt.InitializeILRuntime(Appdomain); }
void LoadHotFixAssembly() { appdomain = new AppDomain(); pdb = null; //编译模式 if (!Assets.runtimeMode) { if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll")) { fs = new MemoryStream(DLLMgr.FileToByte("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll")); } else { Log.PrintWarning("DLL文件不存在"); return; } //查看是否有PDB文件 if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb")) { pdb = new MemoryStream(DLLMgr.FileToByte("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb")); } } else//解密加载 { var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset)); if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; try { var original = CryptoHelper.AesDecrypt(dll.bytes, Key); fs = new MemoryStream(original); } catch (Exception ex) { Log.PrintError("加载热更DLL失败,可能是解密密码不正确"); Log.PrintError("加载热更DLL错误:\n" + ex.Message); return; } } try { appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); Log.PrintError("加载热更DLL错误:\n" + e.Message); return; } InitILrt.InitializeILRuntime(appdomain); OnHotFixLoaded(); }
void LoadHotFixAssembly() { appdomain = new AppDomain(); if (!Assets.runtimeMode) { DLLMgr.MakeBytes(); } var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset)); if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; byte[] original = dll.bytes; try { if (!Assets.runtimeMode) { original = CryptoHelper.AesDecrypt(original, "DevelopmentMode."); } else { original = CryptoHelper.AesDecrypt(original, Key); } } catch (Exception ex) { Log.PrintError("加载热更DLL失败,可能是解密密码不正确"); Log.PrintError("加载热更DLL错误:\n" + ex.Message); return; } fs = new MemoryStream(original); MemoryStream pdb = null; #if UNITY_EDITOR if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb")) { try { pdb = new MemoryStream(AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb").bytes); } catch { } } #endif try { appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); Log.PrintError("加载热更DLL错误:\n" + e.Message); return; } InitILrt.InitializeILRuntime(appdomain); OnHotFixLoaded(); }
public static void RunGame() { /* * ==================================== * DO NOT DELETE THIS * ==================================== */ InitILrt.BindAllScripts(); return; /* * ==================================== * Demos * ==================================== */ /* * ==================================== * JResource EXAMPLE * ==================================== */ var txt = JResource.LoadRes <TextAsset>("Text.txt"); Log.Print("Get Resource with Sync method: " + txt.text); JResource.LoadResAsync <TextAsset>("Text.txt", (txt) => { Log.Print("Get Resource with Async method: " + txt.text); }); /* * ==================================== * JAction EXAMPLE * ==================================== */ int num = 0; int repeatCounts = 3; float repeatDuration = 0.5f; float timeout = 10f; //Simple use JAction j = new JAction(); j.Do(() => Log.Print("[j] Hello from JAction!")) .Execute(); //Until JAction j1 = new JAction(); j1.Until(() => true) .Do(() => Log.Print("[j1] until condition has done")) .Execute(); //Repeat JAction j2 = new JAction(); j2.Repeat(() => { num++; Log.Print($"[j2] num is: {num}"); }, repeatCounts, repeatDuration) .Execute(); //Repeat when JAction j3 = new JAction(); j3.RepeatWhen(() => { Log.Print($"[j3] num is more than 0, num--"); num--; }, () => num > 0, repeatDuration, timeout) .Execute(); //Repeat until JAction j4 = new JAction(); j4.RepeatUntil(() => { Log.Print($"[j4] num is less than 3, num++"); num++; }, () => num < 3, repeatDuration, timeout) .Execute(); //Delay JAction j5 = new JAction(); j5.Do(() => Log.Print("[j5] JAction will do something else in 3 seconds")) .Delay(3.0f) .Do(() => Log.Print("[j5] Bye from JAction")) .Execute(); //Execute Async JAction j6 = new JAction(); _ = j6.Do(() => Log.Print("[j6] This is an async JAction")) .ExecuteAsync(); //Execute Async With Callback JAction j7 = new JAction(); j7.Do(() => Log.Print("[j7] This is an async JAction but runs parallel, callback will be called after it has done")) .ExecuteAsync(() => Log.Print("[j7] Done")); //Cancel a JAction JAction j8 = new JAction(); j8.RepeatWhen(() => Log.Print("[j8] I am repeating!!!"), () => true, 1, timeout) .ExecuteAsync(); //You can either add a cancel callback j8.OnCancel(() => Log.Print("[j8] has been cancelled!")); JAction j9 = new JAction(); j9.Delay(5) .Do(() => { j8.Cancel(); Log.Print("[j9] cancelled j8"); }) .Execute(); //Reset a JAction j1.Reset(); Transform Canvas = GameObject.Find("Canvas").transform; /* * ==================================== * JUI LOOP EXAMPLE * ==================================== */ var JUILoopExampleGO = new GameObject("JUILoopExampleBtn"); JUILoopExampleGO.transform.SetParent(Canvas, false); var JUILoopExampleText = JUILoopExampleGO.AddComponent <Text>(); JUILoopExampleText.text = "[Press me to see LOOP example]"; JUILoopExampleText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; JUILoopExampleText.fontSize = 30; JUILoopExampleText.color = Color.red; JUILoopExampleText.alignment = TextAnchor.MiddleCenter; JUILoopExampleGO.GetComponent <RectTransform>().sizeDelta = new Vector2(500, 75); JUILoopExampleGO.GetComponent <RectTransform>().anchoredPosition = new Vector2(-250, -100); var JUILoopExampleBtn = JUILoopExampleGO.AddComponent <Button>(); JUILoopExampleBtn.onClick.AddListener( () => { var JUILoopBG = new GameObject("JUILoopBG").AddComponent <Image>(); JUILoopBG.transform.SetParent(Canvas); JUILoopBG.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width, Screen.height); JUILoopBG.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); JUILoopBG.color = new Color(0.2f, 0.2f, 0.2f); GameObject Showcase = new GameObject("CountdownShowcase"); //JUI DEMO int i = 10; var JUI = Showcase.AddComponent <JUI>() .onInit(t => { Log.Print("JUI Loop Example has been inited"); var text = t.Element <Text>(); Showcase.transform.SetParent(JUILoopBG.transform); Showcase.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width, 100); Showcase.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); text.text = "I will be sestroyed in 10 seconds"; text.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; text.fontSize = 50; text.color = Color.white; text.alignment = TextAnchor.MiddleCenter; t.FrameMode = false; //Run in ms t.Frequency = 1000; //Loop each 1s UnityEngine.Object.Destroy(JUILoopBG.gameObject, 10); }) .onLoop(t1 => { i--; t1.Element <Text>().text = "I will be destroyed in " + i + " seconds"; Log.Print("JUI Loop Example is doing loop!"); }) .onEnd(t2 => { Log.Print("JUI Loop Example has been destroyed!"); }) .Activate(); }); /* * ==================================== * JUI Bind EXAMPLE * ==================================== */ var JUIBindExampleGO = new GameObject("JUIBindExampleBtn"); JUIBindExampleGO.transform.SetParent(Canvas, false); var JUIBindExampleText = JUIBindExampleGO.AddComponent <Text>(); JUIBindExampleText.text = "[Press me to see BIND example]"; JUIBindExampleText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; JUIBindExampleText.fontSize = 30; JUIBindExampleText.color = Color.red; JUIBindExampleText.alignment = TextAnchor.MiddleCenter; JUIBindExampleGO.GetComponent <RectTransform>().sizeDelta = new Vector2(500, 75); JUIBindExampleGO.GetComponent <RectTransform>().anchoredPosition = new Vector2(250, -100); var JUIBindExampleBtn = JUIBindExampleGO.AddComponent <Button>(); JUIBindExampleBtn.onClick.AddListener( () => { var JUIBindBG = new GameObject("JUIBindBG").AddComponent <Image>(); JUIBindBG.transform.SetParent(Canvas); JUIBindBG.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width, Screen.height); JUIBindBG.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0); JUIBindBG.color = new Color(0.2f, 0.2f, 0.2f); var Description = new GameObject("Description"); Description.transform.SetParent(JUIBindBG.transform, false); var DescriptionText = Description.AddComponent <Text>(); DescriptionText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; DescriptionText.fontSize = 35; DescriptionText.color = Color.white; DescriptionText.alignment = TextAnchor.MiddleCenter; Description.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width, 75); Description.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 50); DescriptionText.text = "Below is a JUI Bind demo, which data updates in each second"; var A = new GameObject("A"); A.transform.SetParent(JUIBindBG.transform, false); var AText = A.AddComponent <Text>(); AText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; AText.fontSize = 27; AText.color = Color.red; AText.alignment = TextAnchor.MiddleCenter; A.GetComponent <RectTransform>().sizeDelta = new Vector2(500, 75); A.GetComponent <RectTransform>().anchoredPosition = new Vector2(-250, -100); var B = new GameObject("B"); B.transform.SetParent(JUIBindBG.transform, false); var BText = B.AddComponent <Text>(); BText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; BText.fontSize = 27; BText.color = Color.red; BText.alignment = TextAnchor.MiddleCenter; B.GetComponent <RectTransform>().sizeDelta = new Vector2(500, 75); B.GetComponent <RectTransform>().anchoredPosition = new Vector2(250, -100); JUIBindBG.gameObject.AddComponent <JUIShowcase>(); var Close = new GameObject("Close"); Close.transform.SetParent(JUIBindBG.transform, false); var CloseText = Close.AddComponent <Text>(); CloseText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; CloseText.fontSize = 20; CloseText.color = Color.white; CloseText.alignment = TextAnchor.MiddleCenter; Close.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width, 75); Close.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -300); CloseText.text = "[Close this Example]"; var CloseBtn = Close.AddComponent <Button>(); CloseBtn.onClick.AddListener(() => { UnityEngine.Object.Destroy(JUIBindBG.gameObject); UnityEngine.Object.Destroy(GameObject.Find("BindShowcase")); }); }); /* * ==================================== * JBehaviour Example * ==================================== */ var JBehaviourExampleGO = new GameObject("JBehaviourExampleBtn"); JBehaviourExampleGO.transform.SetParent(Canvas, false); var JBehaviourExampleText = JBehaviourExampleGO.AddComponent <Text>(); JBehaviourExampleText.text = "[Press me to see JBehaviour example]"; JBehaviourExampleText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; JBehaviourExampleText.fontSize = 30; JBehaviourExampleText.color = Color.red; JBehaviourExampleText.alignment = TextAnchor.MiddleCenter; JBehaviourExampleGO.GetComponent <RectTransform>().sizeDelta = new Vector2(1000, 75); JBehaviourExampleGO.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -300); var JBehaviourExampleBtn = JBehaviourExampleGO.AddComponent <Button>(); JBehaviourExampleBtn.onClick.AddListener( () => { new GameObject("JBehaviourShowcase").AddComponent <JBehaviourExample>(); }); }