[refactor] 一些重构

main
walon 2022-10-09 20:53:13 +08:00
parent 7fea92cc75
commit ef83fca9a0
12 changed files with 34 additions and 29 deletions

View File

@ -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中未配置任何热更新模块");
}
}

View File

@ -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))
{

View File

@ -24,7 +24,7 @@ namespace HybridCLR.Editor.Commands
CompileDllCommand.CompileDllActiveBuildTarget();
}
var ls = SettingsUtil.GlobalSettings;
var ls = SettingsUtil.HybridCLRSettings;
var allAssByNames = new Dictionary<string, Assembly>();
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())

View File

@ -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,
});

View File

@ -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}");

View File

@ -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;
}

View File

@ -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}";
}

View File

@ -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<SettingsPresetReceiver>();
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<HybridCLRGlobalSettings>();
Undo.RecordObject(HybridCLRSettings.Instance, "Capture Value for Reset");
var dv = ScriptableObject.CreateInstance<HybridCLRSettings>();
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;
}

View File

@ -2,16 +2,19 @@ using UnityEditorInternal;
using UnityEngine;
namespace HybridCLR.Editor
{
[FilePath("ProjectSettings/HybridCLRGlobalSettings.asset")]
public class HybridCLRGlobalSettings : ScriptableSingleton<HybridCLRGlobalSettings>
[FilePath("ProjectSettings/HybridCLRSettings.asset")]
public class HybridCLRSettings : ScriptableSingleton<HybridCLRSettings>
{
[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")]

View File

@ -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<AssemblyDefinitionAsset>()).Select(ad => JsonUtility.FromJson<AssemblyDefinitionData>(ad.text));
var hotfixAssembles = new List<string>();
@ -77,6 +77,6 @@ namespace HybridCLR.Editor
}
public static List<string> HotUpdateAssemblyFiles => HotUpdateAssemblyNames.Select(dll => dll + ".dll").ToList();
public static HybridCLRGlobalSettings GlobalSettings => HybridCLRGlobalSettings.Instance;
public static HybridCLRSettings HybridCLRSettings => HybridCLRSettings.Instance;
}
}

View File

@ -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",