From ef83fca9a0b3443bcbfdfa68c436603a23e7d945 Mon Sep 17 00:00:00 2001 From: walon Date: Sun, 9 Oct 2022 20:53:13 +0800 Subject: [PATCH] =?UTF-8?q?[refactor]=20=E4=B8=80=E4=BA=9B=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/BuildProcessors/CheckSettings.cs | 8 +++--- .../Commands/AOTReferenceGeneratorCommand.cs | 2 +- Editor/Commands/LinkGeneratorCommand.cs | 2 +- .../Commands/MethodBridgeGeneratorCommand.cs | 2 +- .../ReversePInvokeWrapperGeneratorCommand.cs | 2 +- Editor/Installer/BashUtil.cs | 1 - Editor/Installer/InstallerController.cs | 2 +- Editor/Settings/HybridCLRSettingProvider.cs | 27 ++++++++++--------- ...GlobalSettings.cs => HybridCLRSettings.cs} | 9 ++++--- ...ings.cs.meta => HybridCLRSettings.cs.meta} | 0 Editor/SettingsUtil.cs | 6 ++--- package.json | 2 +- 12 files changed, 34 insertions(+), 29 deletions(-) rename Editor/Settings/{HybridCLRGlobalSettings.cs => HybridCLRSettings.cs} (80%) rename Editor/Settings/{HybridCLRGlobalSettings.cs.meta => HybridCLRSettings.cs.meta} (100%) diff --git a/Editor/BuildProcessors/CheckSettings.cs b/Editor/BuildProcessors/CheckSettings.cs index 76d0a88..85dbdd0 100644 --- a/Editor/BuildProcessors/CheckSettings.cs +++ b/Editor/BuildProcessors/CheckSettings.cs @@ -15,9 +15,9 @@ namespace HybridCLR.Editor.BuildProcessors public void OnPreprocessBuild(BuildReport report) { - HybridCLRGlobalSettings globalSettings = SettingsUtil.GlobalSettings; + HybridCLRSettings globalSettings = SettingsUtil.HybridCLRSettings; #if !UNITY_2020_1_OR_NEWER || !UNITY_IOS - if (!globalSettings.enable || globalSettings.useGlobalIl2Cpp) + if (!globalSettings.enable || globalSettings.useGlobalIl2cpp) { string oldIl2cppPath = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH"); if (!string.IsNullOrEmpty(oldIl2cppPath)) @@ -52,10 +52,10 @@ namespace HybridCLR.Editor.BuildProcessors throw new Exception($"你没有初始化HybridCLR,请通过菜单'HybridCLR/Installer'安装"); } - HybridCLRGlobalSettings gs = SettingsUtil.GlobalSettings; + HybridCLRSettings gs = SettingsUtil.HybridCLRSettings; if (((gs.hotUpdateAssemblies?.Length + gs.hotUpdateAssemblyDefinitions?.Length) ?? 0) == 0) { - throw new Exception($"GlobalSettings中未配置热更新dll"); + throw new Exception($"HybridCLRSettings中未配置任何热更新模块"); } } diff --git a/Editor/Commands/AOTReferenceGeneratorCommand.cs b/Editor/Commands/AOTReferenceGeneratorCommand.cs index 5e85fe9..a56d12f 100644 --- a/Editor/Commands/AOTReferenceGeneratorCommand.cs +++ b/Editor/Commands/AOTReferenceGeneratorCommand.cs @@ -28,7 +28,7 @@ namespace HybridCLR.Editor.Commands CompileDllCommand.CompileDllActiveBuildTarget(); } - var gs = SettingsUtil.GlobalSettings; + var gs = SettingsUtil.HybridCLRSettings; using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames)) { diff --git a/Editor/Commands/LinkGeneratorCommand.cs b/Editor/Commands/LinkGeneratorCommand.cs index b9cae1d..d30e13a 100644 --- a/Editor/Commands/LinkGeneratorCommand.cs +++ b/Editor/Commands/LinkGeneratorCommand.cs @@ -24,7 +24,7 @@ namespace HybridCLR.Editor.Commands CompileDllCommand.CompileDllActiveBuildTarget(); } - var ls = SettingsUtil.GlobalSettings; + var ls = SettingsUtil.HybridCLRSettings; var allAssByNames = new Dictionary(); foreach (var ass in AppDomain.CurrentDomain.GetAssemblies()) diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index 340b663..67f793a 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -77,7 +77,7 @@ namespace HybridCLR.Editor.Commands { var analyzer = new Analyzer(new Analyzer.Options { - MaxIterationCount = Math.Min(20, SettingsUtil.GlobalSettings.maxMethodBridgeGenericIteration), + MaxIterationCount = Math.Min(20, SettingsUtil.HybridCLRSettings.maxMethodBridgeGenericIteration), Collector = collector, }); diff --git a/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs b/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs index edf59d8..36d7f2a 100644 --- a/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs +++ b/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs @@ -21,7 +21,7 @@ namespace HybridCLR.Editor.Commands { string ReversePInvokeWrapperStubFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/metadata/ReversePInvokeMethodStub.cpp"; string wrapperTemplateStr = File.ReadAllText($"{SettingsUtil.TemplatePathInPackage}/ReversePInvokeMethodStub.cpp.txt"); - int wrapperCount = SettingsUtil.GlobalSettings.ReversePInvokeWrapperCount; + int wrapperCount = SettingsUtil.HybridCLRSettings.ReversePInvokeWrapperCount; var generator = new Generator(); generator.Generate(wrapperTemplateStr, wrapperCount,ReversePInvokeWrapperStubFile); Debug.Log($"GenerateReversePInvokeWrapper. wraperCount:{wrapperCount} output:{ReversePInvokeWrapperStubFile}"); diff --git a/Editor/Installer/BashUtil.cs b/Editor/Installer/BashUtil.cs index 0a6bc21..05770de 100644 --- a/Editor/Installer/BashUtil.cs +++ b/Editor/Installer/BashUtil.cs @@ -57,7 +57,6 @@ namespace HybridCLR.Editor.Installer #elif UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX return RunCommand(".", "which", new string[] {prog}) == 0; #endif - return false; } diff --git a/Editor/Installer/InstallerController.cs b/Editor/Installer/InstallerController.cs index 72730f2..f85f07a 100644 --- a/Editor/Installer/InstallerController.cs +++ b/Editor/Installer/InstallerController.cs @@ -273,7 +273,7 @@ namespace HybridCLR.Editor.Installer private static string GetRepoUrl(string repoName) { - string repoProvider = SettingsUtil.GlobalSettings.cloneFromGitee ? "gitee" : "github"; + string repoProvider = SettingsUtil.HybridCLRSettings.cloneFromGitee ? "gitee" : "github"; return $"https://{repoProvider}.com/focus-creative-games/{repoName}"; } diff --git a/Editor/Settings/HybridCLRSettingProvider.cs b/Editor/Settings/HybridCLRSettingProvider.cs index dd01c83..78ccfd7 100644 --- a/Editor/Settings/HybridCLRSettingProvider.cs +++ b/Editor/Settings/HybridCLRSettingProvider.cs @@ -10,6 +10,7 @@ namespace HybridCLR.Editor { private static SerializedObject m_SerializedObject; private SerializedProperty m_Enable; + private SerializedProperty m_UseGlobalIl2cpp; private SerializedProperty m_CloneFromGitee; private SerializedProperty m_HotUpdateAssemblyDefinitions; private SerializedProperty m_HotUpdateAssemblies; @@ -22,11 +23,12 @@ namespace HybridCLR.Editor public HybridCLRSettingsProvider() : base("Project/HybridCLR Settings", SettingsScope.Project) { } public override void OnActivate(string searchContext, VisualElement rootElement) { - HybridCLRGlobalSettings.Instance.Save(); - var setting = HybridCLRGlobalSettings.Instance; + HybridCLRSettings.Instance.Save(); + var setting = HybridCLRSettings.Instance; setting.hideFlags &= ~HideFlags.NotEditable; m_SerializedObject ??= new SerializedObject(setting); m_Enable = m_SerializedObject.FindProperty("enable"); + m_UseGlobalIl2cpp = m_SerializedObject.FindProperty("useGlobalIl2cpp"); m_CloneFromGitee = m_SerializedObject.FindProperty("cloneFromGitee"); m_HotUpdateAssemblyDefinitions = m_SerializedObject.FindProperty("hotUpdateAssemblyDefinitions"); m_HotUpdateAssemblies = m_SerializedObject.FindProperty("hotUpdateAssemblies"); @@ -61,7 +63,7 @@ namespace HybridCLR.Editor content.tooltip = "点击存储或加载 Preset ."; if (GUI.Button(rect, content, buttonStyle)) { - var target = HybridCLRGlobalSettings.Instance; + var target = HybridCLRSettings.Instance; var receiver = ScriptableObject.CreateInstance(); receiver.Init(target); PresetSelector.ShowSelector(target, null, true, receiver); @@ -76,11 +78,11 @@ namespace HybridCLR.Editor GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Reset"), false, () => { - Undo.RecordObject(HybridCLRGlobalSettings.Instance, "Capture Value for Reset"); - var dv = ScriptableObject.CreateInstance(); + Undo.RecordObject(HybridCLRSettings.Instance, "Capture Value for Reset"); + var dv = ScriptableObject.CreateInstance(); var json = EditorJsonUtility.ToJson(dv); - EditorJsonUtility.FromJsonOverwrite(json,HybridCLRGlobalSettings.Instance); - HybridCLRGlobalSettings.Instance.Save(); + EditorJsonUtility.FromJsonOverwrite(json,HybridCLRSettings.Instance); + HybridCLRSettings.Instance.Save(); }); menu.ShowAsContext(); } @@ -93,12 +95,13 @@ namespace HybridCLR.Editor if (m_SerializedObject == null || !m_SerializedObject.targetObject) { m_SerializedObject = null; - m_SerializedObject = new SerializedObject(HybridCLRGlobalSettings.Instance); + m_SerializedObject = new SerializedObject(HybridCLRSettings.Instance); } m_SerializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_Enable); EditorGUILayout.PropertyField(m_CloneFromGitee); + EditorGUILayout.PropertyField(m_UseGlobalIl2cpp); EditorGUILayout.PropertyField(m_HotUpdateAssemblyDefinitions); EditorGUILayout.PropertyField(m_HotUpdateAssemblies); EditorGUILayout.PropertyField(m_OutputLinkFile); @@ -109,7 +112,7 @@ namespace HybridCLR.Editor if (EditorGUI.EndChangeCheck()) { m_SerializedObject.ApplyModifiedProperties(); - HybridCLRGlobalSettings.Instance.Save(); + HybridCLRSettings.Instance.Save(); } } } @@ -122,17 +125,17 @@ namespace HybridCLR.Editor public override void OnDeactivate() { base.OnDeactivate(); - HybridCLRGlobalSettings.Instance.Save(); + HybridCLRSettings.Instance.Save(); m_SerializedObject = null; } [SettingsProvider] public static SettingsProvider CreateMyCustomSettingsProvider() { - if (HybridCLRGlobalSettings.Instance) + if (HybridCLRSettings.Instance) { var provider = new HybridCLRSettingsProvider { - keywords = GetSearchKeywordsFromSerializedObject(m_SerializedObject ??= new SerializedObject(HybridCLRGlobalSettings.Instance)) + keywords = GetSearchKeywordsFromSerializedObject(m_SerializedObject ??= new SerializedObject(HybridCLRSettings.Instance)) }; return provider; } diff --git a/Editor/Settings/HybridCLRGlobalSettings.cs b/Editor/Settings/HybridCLRSettings.cs similarity index 80% rename from Editor/Settings/HybridCLRGlobalSettings.cs rename to Editor/Settings/HybridCLRSettings.cs index 0b7f900..a0f6ea8 100644 --- a/Editor/Settings/HybridCLRGlobalSettings.cs +++ b/Editor/Settings/HybridCLRSettings.cs @@ -2,16 +2,19 @@ using UnityEditorInternal; using UnityEngine; namespace HybridCLR.Editor { - [FilePath("ProjectSettings/HybridCLRGlobalSettings.asset")] - public class HybridCLRGlobalSettings : ScriptableSingleton + [FilePath("ProjectSettings/HybridCLRSettings.asset")] + public class HybridCLRSettings : ScriptableSingleton { [Header("开启HybridCLR插件")] public bool enable = true; + [Header("使用全局安装的il2cpp")] + public bool useGlobalIl2cpp; + [Header("从gitee clone插件代码")] public bool cloneFromGitee = true; // false 则从github上拉取 - [Header("热更新Assembly Definition Modules")] + [Header("热更新Assembly Definitions")] public AssemblyDefinitionAsset[] hotUpdateAssemblyDefinitions; [Header("热更新dlls")] diff --git a/Editor/Settings/HybridCLRGlobalSettings.cs.meta b/Editor/Settings/HybridCLRSettings.cs.meta similarity index 100% rename from Editor/Settings/HybridCLRGlobalSettings.cs.meta rename to Editor/Settings/HybridCLRSettings.cs.meta diff --git a/Editor/SettingsUtil.cs b/Editor/SettingsUtil.cs index b98e0a4..34dc245 100644 --- a/Editor/SettingsUtil.cs +++ b/Editor/SettingsUtil.cs @@ -11,7 +11,7 @@ namespace HybridCLR.Editor { public static class SettingsUtil { - public static bool Enable => HybridCLRGlobalSettings.Instance.enable; + public static bool Enable => HybridCLRSettings.Instance.enable; public static string PackageName { get; } = "com.focus-creative-games.hybridclr_unity"; @@ -63,7 +63,7 @@ namespace HybridCLR.Editor { get { - var gs = HybridCLRGlobalSettings.Instance; + var gs = HybridCLRSettings.Instance; var hotfixAssNames = (gs.hotUpdateAssemblyDefinitions ?? Array.Empty()).Select(ad => JsonUtility.FromJson(ad.text)); var hotfixAssembles = new List(); @@ -77,6 +77,6 @@ namespace HybridCLR.Editor } public static List HotUpdateAssemblyFiles => HotUpdateAssemblyNames.Select(dll => dll + ".dll").ToList(); - public static HybridCLRGlobalSettings GlobalSettings => HybridCLRGlobalSettings.Instance; + public static HybridCLRSettings HybridCLRSettings => HybridCLRSettings.Instance; } } diff --git a/package.json b/package.json index 0268fd9..8ac6e9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "0.3.7", + "version": "0.3.8", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",