From bf6ae99dadfbc64e3a6f2dc7f63509a5b6b12621 Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 26 Jan 2023 13:11:38 +0800 Subject: [PATCH] =?UTF-8?q?[change]=20=E7=9B=B4=E6=8E=A5=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BA=86=E6=AF=8F=E4=B8=AAunity=E5=A4=A7=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84hybridclr=E5=8F=8Ail2cpp=5Fplus?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E9=81=BF=E5=85=8D=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E4=BA=86=E4=B8=8D=E5=85=BC=E5=AE=B9=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Data~/hybridclr_version.json | 19 +++ Editor/Installer/InstallerController.cs | 175 ++++++++++-------------- Editor/Installer/InstallerWindow.cs | 63 +++------ package.json | 2 +- 4 files changed, 107 insertions(+), 152 deletions(-) create mode 100644 Data~/hybridclr_version.json diff --git a/Data~/hybridclr_version.json b/Data~/hybridclr_version.json new file mode 100644 index 0000000..434c8e4 --- /dev/null +++ b/Data~/hybridclr_version.json @@ -0,0 +1,19 @@ +{ + "versions": [ + { + "unity_version":"2019", + "hybridclr" : { "branch":"main", "hash":"531f98365eebce5d1390175be2b41c41e217d918"}, + "il2cpp_plus": { "branch":"2019-main", "hash":"ebe5190b0404d1857832bd1d52ebec7c3730a01d"} + }, + { + "unity_version":"2020", + "hybridclr" : { "branch":"main", "hash":"531f98365eebce5d1390175be2b41c41e217d918"}, + "il2cpp_plus": { "branch":"2020-main", "hash":"c6cf54285381d0b03a58126e0d39b6e4d11937b7"} + }, + { + "unity_version":"2021", + "hybridclr" : { "branch":"main", "hash":"531f98365eebce5d1390175be2b41c41e217d918"}, + "il2cpp_plus": { "branch":"2021-main", "hash":"99cd1cbbfc1f637460379e81c9a7776cd3e662ad"} + } + ] +} \ No newline at end of file diff --git a/Editor/Installer/InstallerController.cs b/Editor/Installer/InstallerController.cs index c2e255e..a163e88 100644 --- a/Editor/Installer/InstallerController.cs +++ b/Editor/Installer/InstallerController.cs @@ -20,24 +20,60 @@ namespace HybridCLR.Editor.Installer Ok, } - public partial class InstallerController + + + + public class InstallerController { private const string hybridclr_repo_path = "hybridclr_repo"; private const string il2cpp_plus_repo_path = "il2cpp_plus_repo"; - - public int MajorVersion => _curVersion.major; - private UnityVersion _curVersion; + private readonly UnityVersion _curVersion; + + private readonly HybridclrVersionManifest _versionManifest; + private readonly HybridclrVersionInfo _curDefaultVersion; public InstallerController() { _curVersion = ParseUnityVersion(Application.unityVersion); + _versionManifest = GetHybridCLRVersionManifest(); + _curDefaultVersion = _versionManifest.versions.Find(v => v.unity_version == _curVersion.major.ToString()); } - public class UnityVersion + private HybridclrVersionManifest GetHybridCLRVersionManifest() + { + string versionFile = $"{SettingsUtil.ProjectDir}/{SettingsUtil.HybridCLRDataPathInPackage}/hybridclr_version.json"; + return JsonUtility.FromJson(File.ReadAllText(versionFile, Encoding.UTF8)); + } + + [Serializable] + class VersionDesc + { + public string branch; + + public string hash; + } + + [Serializable] + class HybridclrVersionInfo + { + public string unity_version; + + public VersionDesc hybridclr; + + public VersionDesc il2cpp_plus; + } + + [Serializable] + class HybridclrVersionManifest + { + public List versions; + } + + private class UnityVersion { public int major; public int minor1; @@ -120,75 +156,22 @@ namespace HybridCLR.Editor.Installer } } - private string _hybridclrLocalVersion; + public string HybridclrLocalVersion => _curDefaultVersion.hybridclr.hash; - public string HybridclrLocalVersion => _hybridclrLocalVersion != null ? _hybridclrLocalVersion : _hybridclrLocalVersion = GetHybridCLRLocalVersion(); + public string Il2cppPlusLocalVersion => _curDefaultVersion.il2cpp_plus.hash; - public string HybridCLRRepoInstalledVersion - { - get { return EditorPrefs.GetString($"hybridclr_repo#{MajorVersion}"); } - set { EditorPrefs.SetString($"hybridclr_repo#{MajorVersion}", value); } - } - - public string Il2CppRepoInstalledVersion - { - get { return EditorPrefs.GetString($"il2cpp_plus_repo#{MajorVersion}"); } - set { EditorPrefs.SetString($"il2cpp_plus_repo#{MajorVersion}", value); } - } - - - private string GetHybridCLRLocalVersion() - { - string workDir = SettingsUtil.HybridCLRDataDir; - string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}"; - if (Directory.Exists(hybridclrRepoDir)) - { - var ret = BashUtil.RunCommand2(hybridclrRepoDir, "git", - new string[] { "log", "HEAD", "-n", "1", "--pretty=format:\"%H\"", }, - false); - if (ret.ExitCode == 0) - { - return ret.StdOut.Trim(); - } - else - { - return "ERROR"; - } - } - return ""; - } - - private string _il2cppPlusLocalVersion; - - public string Il2cppPlusLocalVersion => _il2cppPlusLocalVersion != null ? _il2cppPlusLocalVersion : _il2cppPlusLocalVersion = GetIl2cppPlusLocalVersion(); - - private string GetIl2cppPlusLocalVersion() - { - string workDir = SettingsUtil.HybridCLRDataDir; - string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}"; - if (Directory.Exists(il2cppPlusRepoDir)) - { - var ret = BashUtil.RunCommand2(il2cppPlusRepoDir, "git", - new string[] { "log", "HEAD", "-n", "1", "--pretty=format:\"%H\"", }, - false); - if (ret.ExitCode == 0) - { - return ret.StdOut.Trim(); - } - else - { - return "ERROR"; - } - } - return ""; - } - private string GetIl2CppPathByContentPath(string contentPath) { return $"{contentPath}/il2cpp"; } + + public void InstallDefaultHybridCLR() + { + InstallLocalHybridCLR(HybridclrLocalVersion, Il2cppPlusLocalVersion); + } + public void InstallLocalHybridCLR(string hybridclrVer, string il2cppPlusVer) { RunInitLocalIl2CppData(GetIl2CppPathByContentPath(EditorApplication.applicationContentsPath), _curVersion, hybridclrVer, il2cppPlusVer); @@ -218,8 +201,20 @@ namespace HybridCLR.Editor.Installer #endif } + void CloneSpeicificCommitId(string workDir, string repoUrl, string branch, string repoDir, string commitId) + { + BashUtil.RemoveDir(repoDir); + BashUtil.RunCommand(workDir, "git", new string[] {"clone", "-b", branch, repoUrl, repoDir}); + BashUtil.RunCommand($"{repoDir}", "git", new string[] { "checkout", commitId }); + } + private void RunInitLocalIl2CppData(string editorIl2cppPath, UnityVersion version, string hybridclrVer, string il2cppPlusVer) { + if (!IsComaptibleVersion()) + { + Debug.LogError($"il2cpp 版本不兼容,最小版本为 {GetCurrentUnityVersionMinCompatibleVersionStr()}"); + return; + } string workDir = SettingsUtil.HybridCLRDataDir; Directory.CreateDirectory(workDir); //BashUtil.RecreateDir(workDir); @@ -231,44 +226,12 @@ namespace HybridCLR.Editor.Installer // clone hybridclr string hybridclrRepoURL = HybridCLRSettings.Instance.hybridclrRepoURL; string hybridclrRepoDir = $"{workDir}/{hybridclr_repo_path}"; - { - BashUtil.RemoveDir(hybridclrRepoDir); - string[] args = new string[] - { - "clone", - "--depth=1", - "-b", - hybridclrVer, - hybridclrRepoURL, - hybridclrRepoDir, - }; - var ret = BashUtil.RunCommand(workDir, "git", args); - //if (ret != 0) - //{ - // throw new Exception($"git clone 失败"); - //} - } + CloneSpeicificCommitId(workDir, hybridclrRepoURL, _curDefaultVersion.hybridclr.branch, hybridclrRepoDir, hybridclrVer); // clone il2cpp_plus string il2cppPlusRepoURL = HybridCLRSettings.Instance.il2cppPlusRepoURL; string il2cppPlusRepoDir = $"{workDir}/{il2cpp_plus_repo_path}"; - { - BashUtil.RemoveDir(il2cppPlusRepoDir); - string[] args = new string[] - { - "clone", - "--depth=1", - "-b", - il2cppPlusVer, - il2cppPlusRepoURL, - il2cppPlusRepoDir, - }; - var ret = BashUtil.RunCommand(workDir, "git", args); - //if (ret != 0) - //{ - // throw new Exception($"git clone 失败"); - //} - } + CloneSpeicificCommitId(workDir, il2cppPlusRepoURL, _curDefaultVersion.il2cpp_plus.branch, il2cppPlusRepoDir, il2cppPlusVer); // create LocalIl2Cpp string localUnityDataDir = SettingsUtil.LocalUnityDataDir; @@ -303,17 +266,17 @@ namespace HybridCLR.Editor.Installer Debug.LogError($"未找到当前版本:{curVersionStr} 对应的改造过的 Unity.IL2CPP.dll,打包出的程序将会崩溃"); } } + if (version.major >= 2021) + { + Debug.LogError($"如果需要打包iOS,必须手动替换UnityEditor.CoreModule.dll为修改后的版本,否则无法获得AOT dlls。详见 https://focus-creative-games.github.io/hybridclr/modify_unity_dll/#unityeditor-coremodule-dll"); + } if (HasInstalledHybridCLR()) { - Debug.Log("安装成功!"); - _hybridclrLocalVersion = null; - _il2cppPlusLocalVersion = null; - HybridCLRRepoInstalledVersion = hybridclrVer; - Il2CppRepoInstalledVersion = il2cppPlusVer; + Debug.Log("安装成功"); } else { - Debug.LogError("安装失败!"); + Debug.LogError("安装失败"); } } } diff --git a/Editor/Installer/InstallerWindow.cs b/Editor/Installer/InstallerWindow.cs index 0b3d1d5..f1f5ece 100644 --- a/Editor/Installer/InstallerWindow.cs +++ b/Editor/Installer/InstallerWindow.cs @@ -10,22 +10,9 @@ namespace HybridCLR.Editor.Installer { private InstallerController _controller; - string _hybridclrVersion; - string _il2cppPlusVersion; - private void OnEnable() { _controller = new InstallerController(); - _hybridclrVersion = _controller.HybridCLRRepoInstalledVersion; - if (string.IsNullOrWhiteSpace(_hybridclrVersion)) - { - _hybridclrVersion = "main"; - } - _il2cppPlusVersion = _controller.Il2CppRepoInstalledVersion; - if (string.IsNullOrWhiteSpace(_il2cppPlusVersion)) - { - _il2cppPlusVersion = $"{_controller.MajorVersion}-main"; - } } private void OnGUI() @@ -44,34 +31,33 @@ namespace HybridCLR.Editor.Installer SettingsService.OpenProjectSettings("Project/HybridCLR Settings"); } + bool hasInstall = _controller.HasInstalledHybridCLR(); + GUILayout.Space(10f); EditorGUILayout.BeginVertical("box"); - bool hasInstall = _controller.HasInstalledHybridCLR(); EditorGUILayout.LabelField($"安装状态:{(hasInstall ? "已安装" : "未安装")}", EditorStyles.boldLabel); + GUILayout.Space(10f); - if (hasInstall) - { - EditorGUILayout.LabelField($"HybridCLR 版本: {_controller.HybridclrLocalVersion}"); - GUILayout.Space(5f); - EditorGUILayout.LabelField($"il2cpp_plus 版本: {_controller.Il2cppPlusLocalVersion}"); - GUILayout.Space(5f); - //GUIInstallButton("检查更新", "检查", UpdateHybridCLR); - //GUILayout.Space(40f); - } + EditorGUILayout.LabelField($"HybridCLR 版本: {_controller.HybridclrLocalVersion}"); + GUILayout.Space(5f); + EditorGUILayout.LabelField($"il2cpp_plus 版本: {_controller.Il2cppPlusLocalVersion}"); + GUILayout.Space(5f); + //GUIInstallButton("检查更新", "检查", UpdateHybridCLR); + //GUILayout.Space(40f); GUILayout.Space(10f); - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField("待安装的 hybridclr 仓库版本号(或branch或tag)(默认取最新版本):", GUILayout.MaxWidth(400)); - _hybridclrVersion = EditorGUILayout.TextField(_hybridclrVersion); - EditorGUILayout.EndHorizontal(); + //EditorGUILayout.BeginHorizontal(); + //EditorGUILayout.LabelField("待安装的 hybridclr 仓库版本号(或branch或tag)(默认取最新版本):", GUILayout.MaxWidth(400)); + //_hybridclrVersion = EditorGUILayout.TextField(_hybridclrVersion); + //EditorGUILayout.EndHorizontal(); - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField($"待安装的 il2cpp_plus 仓库版本号(或branch或tag)(默认取{_controller.MajorVersion}-main分支最新版本):", GUILayout.MaxWidth(400)); - _il2cppPlusVersion = EditorGUILayout.TextField(_il2cppPlusVersion); - EditorGUILayout.EndHorizontal(); + //EditorGUILayout.BeginHorizontal(); + //EditorGUILayout.LabelField($"待安装的 il2cpp_plus 仓库版本号(或branch或tag)(默认取{_controller.MajorVersion}-main分支最新版本):", GUILayout.MaxWidth(400)); + //_il2cppPlusVersion = EditorGUILayout.TextField(_il2cppPlusVersion); + //EditorGUILayout.EndHorizontal(); GUIInstallButton("安装hybridclr+il2cpp_plus代码到本地目录", "安装"); @@ -93,20 +79,7 @@ namespace HybridCLR.Editor.Installer private void InstallLocalHybridCLR() { - if (!_controller.IsComaptibleVersion()) - { - Debug.LogError($"il2cpp 版本不兼容,最小版本为 {_controller.GetCurrentUnityVersionMinCompatibleVersionStr()}"); - return; - } - if (string.IsNullOrWhiteSpace(_hybridclrVersion)) - { - _hybridclrVersion = "main"; - } - if (string.IsNullOrWhiteSpace(_il2cppPlusVersion)) - { - _il2cppPlusVersion = $"{_controller.MajorVersion}-main"; - } - _controller.InstallLocalHybridCLR(_hybridclrVersion, _il2cppPlusVersion); + _controller.InstallDefaultHybridCLR(); } } } diff --git a/package.json b/package.json index 296f127..310492b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "1.1.19", + "version": "1.1.20", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",