[refactor] 一些重构
parent
7fea92cc75
commit
ef83fca9a0
|
@ -15,9 +15,9 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||||
|
|
||||||
public void OnPreprocessBuild(BuildReport report)
|
public void OnPreprocessBuild(BuildReport report)
|
||||||
{
|
{
|
||||||
HybridCLRGlobalSettings globalSettings = SettingsUtil.GlobalSettings;
|
HybridCLRSettings globalSettings = SettingsUtil.HybridCLRSettings;
|
||||||
#if !UNITY_2020_1_OR_NEWER || !UNITY_IOS
|
#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");
|
string oldIl2cppPath = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
|
||||||
if (!string.IsNullOrEmpty(oldIl2cppPath))
|
if (!string.IsNullOrEmpty(oldIl2cppPath))
|
||||||
|
@ -52,10 +52,10 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||||
throw new Exception($"你没有初始化HybridCLR,请通过菜单'HybridCLR/Installer'安装");
|
throw new Exception($"你没有初始化HybridCLR,请通过菜单'HybridCLR/Installer'安装");
|
||||||
}
|
}
|
||||||
|
|
||||||
HybridCLRGlobalSettings gs = SettingsUtil.GlobalSettings;
|
HybridCLRSettings gs = SettingsUtil.HybridCLRSettings;
|
||||||
if (((gs.hotUpdateAssemblies?.Length + gs.hotUpdateAssemblyDefinitions?.Length) ?? 0) == 0)
|
if (((gs.hotUpdateAssemblies?.Length + gs.hotUpdateAssemblyDefinitions?.Length) ?? 0) == 0)
|
||||||
{
|
{
|
||||||
throw new Exception($"GlobalSettings中未配置热更新dll");
|
throw new Exception($"HybridCLRSettings中未配置任何热更新模块");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace HybridCLR.Editor.Commands
|
||||||
CompileDllCommand.CompileDllActiveBuildTarget();
|
CompileDllCommand.CompileDllActiveBuildTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
var gs = SettingsUtil.GlobalSettings;
|
var gs = SettingsUtil.HybridCLRSettings;
|
||||||
|
|
||||||
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames))
|
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames))
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace HybridCLR.Editor.Commands
|
||||||
CompileDllCommand.CompileDllActiveBuildTarget();
|
CompileDllCommand.CompileDllActiveBuildTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
var ls = SettingsUtil.GlobalSettings;
|
var ls = SettingsUtil.HybridCLRSettings;
|
||||||
|
|
||||||
var allAssByNames = new Dictionary<string, Assembly>();
|
var allAssByNames = new Dictionary<string, Assembly>();
|
||||||
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
|
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace HybridCLR.Editor.Commands
|
||||||
{
|
{
|
||||||
var analyzer = new Analyzer(new Analyzer.Options
|
var analyzer = new Analyzer(new Analyzer.Options
|
||||||
{
|
{
|
||||||
MaxIterationCount = Math.Min(20, SettingsUtil.GlobalSettings.maxMethodBridgeGenericIteration),
|
MaxIterationCount = Math.Min(20, SettingsUtil.HybridCLRSettings.maxMethodBridgeGenericIteration),
|
||||||
Collector = collector,
|
Collector = collector,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace HybridCLR.Editor.Commands
|
||||||
{
|
{
|
||||||
string ReversePInvokeWrapperStubFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/metadata/ReversePInvokeMethodStub.cpp";
|
string ReversePInvokeWrapperStubFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/metadata/ReversePInvokeMethodStub.cpp";
|
||||||
string wrapperTemplateStr = File.ReadAllText($"{SettingsUtil.TemplatePathInPackage}/ReversePInvokeMethodStub.cpp.txt");
|
string wrapperTemplateStr = File.ReadAllText($"{SettingsUtil.TemplatePathInPackage}/ReversePInvokeMethodStub.cpp.txt");
|
||||||
int wrapperCount = SettingsUtil.GlobalSettings.ReversePInvokeWrapperCount;
|
int wrapperCount = SettingsUtil.HybridCLRSettings.ReversePInvokeWrapperCount;
|
||||||
var generator = new Generator();
|
var generator = new Generator();
|
||||||
generator.Generate(wrapperTemplateStr, wrapperCount,ReversePInvokeWrapperStubFile);
|
generator.Generate(wrapperTemplateStr, wrapperCount,ReversePInvokeWrapperStubFile);
|
||||||
Debug.Log($"GenerateReversePInvokeWrapper. wraperCount:{wrapperCount} output:{ReversePInvokeWrapperStubFile}");
|
Debug.Log($"GenerateReversePInvokeWrapper. wraperCount:{wrapperCount} output:{ReversePInvokeWrapperStubFile}");
|
||||||
|
|
|
@ -57,7 +57,6 @@ namespace HybridCLR.Editor.Installer
|
||||||
#elif UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
|
#elif UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
|
||||||
return RunCommand(".", "which", new string[] {prog}) == 0;
|
return RunCommand(".", "which", new string[] {prog}) == 0;
|
||||||
#endif
|
#endif
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -273,7 +273,7 @@ namespace HybridCLR.Editor.Installer
|
||||||
|
|
||||||
private static string GetRepoUrl(string repoName)
|
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}";
|
return $"https://{repoProvider}.com/focus-creative-games/{repoName}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace HybridCLR.Editor
|
||||||
{
|
{
|
||||||
private static SerializedObject m_SerializedObject;
|
private static SerializedObject m_SerializedObject;
|
||||||
private SerializedProperty m_Enable;
|
private SerializedProperty m_Enable;
|
||||||
|
private SerializedProperty m_UseGlobalIl2cpp;
|
||||||
private SerializedProperty m_CloneFromGitee;
|
private SerializedProperty m_CloneFromGitee;
|
||||||
private SerializedProperty m_HotUpdateAssemblyDefinitions;
|
private SerializedProperty m_HotUpdateAssemblyDefinitions;
|
||||||
private SerializedProperty m_HotUpdateAssemblies;
|
private SerializedProperty m_HotUpdateAssemblies;
|
||||||
|
@ -22,11 +23,12 @@ namespace HybridCLR.Editor
|
||||||
public HybridCLRSettingsProvider() : base("Project/HybridCLR Settings", SettingsScope.Project) { }
|
public HybridCLRSettingsProvider() : base("Project/HybridCLR Settings", SettingsScope.Project) { }
|
||||||
public override void OnActivate(string searchContext, VisualElement rootElement)
|
public override void OnActivate(string searchContext, VisualElement rootElement)
|
||||||
{
|
{
|
||||||
HybridCLRGlobalSettings.Instance.Save();
|
HybridCLRSettings.Instance.Save();
|
||||||
var setting = HybridCLRGlobalSettings.Instance;
|
var setting = HybridCLRSettings.Instance;
|
||||||
setting.hideFlags &= ~HideFlags.NotEditable;
|
setting.hideFlags &= ~HideFlags.NotEditable;
|
||||||
m_SerializedObject ??= new SerializedObject(setting);
|
m_SerializedObject ??= new SerializedObject(setting);
|
||||||
m_Enable = m_SerializedObject.FindProperty("enable");
|
m_Enable = m_SerializedObject.FindProperty("enable");
|
||||||
|
m_UseGlobalIl2cpp = m_SerializedObject.FindProperty("useGlobalIl2cpp");
|
||||||
m_CloneFromGitee = m_SerializedObject.FindProperty("cloneFromGitee");
|
m_CloneFromGitee = m_SerializedObject.FindProperty("cloneFromGitee");
|
||||||
m_HotUpdateAssemblyDefinitions = m_SerializedObject.FindProperty("hotUpdateAssemblyDefinitions");
|
m_HotUpdateAssemblyDefinitions = m_SerializedObject.FindProperty("hotUpdateAssemblyDefinitions");
|
||||||
m_HotUpdateAssemblies = m_SerializedObject.FindProperty("hotUpdateAssemblies");
|
m_HotUpdateAssemblies = m_SerializedObject.FindProperty("hotUpdateAssemblies");
|
||||||
|
@ -61,7 +63,7 @@ namespace HybridCLR.Editor
|
||||||
content.tooltip = "点击存储或加载 Preset .";
|
content.tooltip = "点击存储或加载 Preset .";
|
||||||
if (GUI.Button(rect, content, buttonStyle))
|
if (GUI.Button(rect, content, buttonStyle))
|
||||||
{
|
{
|
||||||
var target = HybridCLRGlobalSettings.Instance;
|
var target = HybridCLRSettings.Instance;
|
||||||
var receiver = ScriptableObject.CreateInstance<SettingsPresetReceiver>();
|
var receiver = ScriptableObject.CreateInstance<SettingsPresetReceiver>();
|
||||||
receiver.Init(target);
|
receiver.Init(target);
|
||||||
PresetSelector.ShowSelector(target, null, true, receiver);
|
PresetSelector.ShowSelector(target, null, true, receiver);
|
||||||
|
@ -76,11 +78,11 @@ namespace HybridCLR.Editor
|
||||||
GenericMenu menu = new GenericMenu();
|
GenericMenu menu = new GenericMenu();
|
||||||
menu.AddItem(new GUIContent("Reset"), false, () =>
|
menu.AddItem(new GUIContent("Reset"), false, () =>
|
||||||
{
|
{
|
||||||
Undo.RecordObject(HybridCLRGlobalSettings.Instance, "Capture Value for Reset");
|
Undo.RecordObject(HybridCLRSettings.Instance, "Capture Value for Reset");
|
||||||
var dv = ScriptableObject.CreateInstance<HybridCLRGlobalSettings>();
|
var dv = ScriptableObject.CreateInstance<HybridCLRSettings>();
|
||||||
var json = EditorJsonUtility.ToJson(dv);
|
var json = EditorJsonUtility.ToJson(dv);
|
||||||
EditorJsonUtility.FromJsonOverwrite(json,HybridCLRGlobalSettings.Instance);
|
EditorJsonUtility.FromJsonOverwrite(json,HybridCLRSettings.Instance);
|
||||||
HybridCLRGlobalSettings.Instance.Save();
|
HybridCLRSettings.Instance.Save();
|
||||||
});
|
});
|
||||||
menu.ShowAsContext();
|
menu.ShowAsContext();
|
||||||
}
|
}
|
||||||
|
@ -93,12 +95,13 @@ namespace HybridCLR.Editor
|
||||||
if (m_SerializedObject == null || !m_SerializedObject.targetObject)
|
if (m_SerializedObject == null || !m_SerializedObject.targetObject)
|
||||||
{
|
{
|
||||||
m_SerializedObject = null;
|
m_SerializedObject = null;
|
||||||
m_SerializedObject = new SerializedObject(HybridCLRGlobalSettings.Instance);
|
m_SerializedObject = new SerializedObject(HybridCLRSettings.Instance);
|
||||||
}
|
}
|
||||||
m_SerializedObject.Update();
|
m_SerializedObject.Update();
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
EditorGUILayout.PropertyField(m_Enable);
|
EditorGUILayout.PropertyField(m_Enable);
|
||||||
EditorGUILayout.PropertyField(m_CloneFromGitee);
|
EditorGUILayout.PropertyField(m_CloneFromGitee);
|
||||||
|
EditorGUILayout.PropertyField(m_UseGlobalIl2cpp);
|
||||||
EditorGUILayout.PropertyField(m_HotUpdateAssemblyDefinitions);
|
EditorGUILayout.PropertyField(m_HotUpdateAssemblyDefinitions);
|
||||||
EditorGUILayout.PropertyField(m_HotUpdateAssemblies);
|
EditorGUILayout.PropertyField(m_HotUpdateAssemblies);
|
||||||
EditorGUILayout.PropertyField(m_OutputLinkFile);
|
EditorGUILayout.PropertyField(m_OutputLinkFile);
|
||||||
|
@ -109,7 +112,7 @@ namespace HybridCLR.Editor
|
||||||
if (EditorGUI.EndChangeCheck())
|
if (EditorGUI.EndChangeCheck())
|
||||||
{
|
{
|
||||||
m_SerializedObject.ApplyModifiedProperties();
|
m_SerializedObject.ApplyModifiedProperties();
|
||||||
HybridCLRGlobalSettings.Instance.Save();
|
HybridCLRSettings.Instance.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,17 +125,17 @@ namespace HybridCLR.Editor
|
||||||
public override void OnDeactivate()
|
public override void OnDeactivate()
|
||||||
{
|
{
|
||||||
base.OnDeactivate();
|
base.OnDeactivate();
|
||||||
HybridCLRGlobalSettings.Instance.Save();
|
HybridCLRSettings.Instance.Save();
|
||||||
m_SerializedObject = null;
|
m_SerializedObject = null;
|
||||||
}
|
}
|
||||||
[SettingsProvider]
|
[SettingsProvider]
|
||||||
public static SettingsProvider CreateMyCustomSettingsProvider()
|
public static SettingsProvider CreateMyCustomSettingsProvider()
|
||||||
{
|
{
|
||||||
if (HybridCLRGlobalSettings.Instance)
|
if (HybridCLRSettings.Instance)
|
||||||
{
|
{
|
||||||
var provider = new HybridCLRSettingsProvider
|
var provider = new HybridCLRSettingsProvider
|
||||||
{
|
{
|
||||||
keywords = GetSearchKeywordsFromSerializedObject(m_SerializedObject ??= new SerializedObject(HybridCLRGlobalSettings.Instance))
|
keywords = GetSearchKeywordsFromSerializedObject(m_SerializedObject ??= new SerializedObject(HybridCLRSettings.Instance))
|
||||||
};
|
};
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,19 @@ using UnityEditorInternal;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
namespace HybridCLR.Editor
|
namespace HybridCLR.Editor
|
||||||
{
|
{
|
||||||
[FilePath("ProjectSettings/HybridCLRGlobalSettings.asset")]
|
[FilePath("ProjectSettings/HybridCLRSettings.asset")]
|
||||||
public class HybridCLRGlobalSettings : ScriptableSingleton<HybridCLRGlobalSettings>
|
public class HybridCLRSettings : ScriptableSingleton<HybridCLRSettings>
|
||||||
{
|
{
|
||||||
[Header("开启HybridCLR插件")]
|
[Header("开启HybridCLR插件")]
|
||||||
public bool enable = true;
|
public bool enable = true;
|
||||||
|
|
||||||
|
[Header("使用全局安装的il2cpp")]
|
||||||
|
public bool useGlobalIl2cpp;
|
||||||
|
|
||||||
[Header("从gitee clone插件代码")]
|
[Header("从gitee clone插件代码")]
|
||||||
public bool cloneFromGitee = true; // false 则从github上拉取
|
public bool cloneFromGitee = true; // false 则从github上拉取
|
||||||
|
|
||||||
[Header("热更新Assembly Definition Modules")]
|
[Header("热更新Assembly Definitions")]
|
||||||
public AssemblyDefinitionAsset[] hotUpdateAssemblyDefinitions;
|
public AssemblyDefinitionAsset[] hotUpdateAssemblyDefinitions;
|
||||||
|
|
||||||
[Header("热更新dlls")]
|
[Header("热更新dlls")]
|
|
@ -11,7 +11,7 @@ namespace HybridCLR.Editor
|
||||||
{
|
{
|
||||||
public static class SettingsUtil
|
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";
|
public static string PackageName { get; } = "com.focus-creative-games.hybridclr_unity";
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ namespace HybridCLR.Editor
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var gs = HybridCLRGlobalSettings.Instance;
|
var gs = HybridCLRSettings.Instance;
|
||||||
var hotfixAssNames = (gs.hotUpdateAssemblyDefinitions ?? Array.Empty<AssemblyDefinitionAsset>()).Select(ad => JsonUtility.FromJson<AssemblyDefinitionData>(ad.text));
|
var hotfixAssNames = (gs.hotUpdateAssemblyDefinitions ?? Array.Empty<AssemblyDefinitionAsset>()).Select(ad => JsonUtility.FromJson<AssemblyDefinitionData>(ad.text));
|
||||||
|
|
||||||
var hotfixAssembles = new List<string>();
|
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 List<string> HotUpdateAssemblyFiles => HotUpdateAssemblyNames.Select(dll => dll + ".dll").ToList();
|
||||||
|
|
||||||
public static HybridCLRGlobalSettings GlobalSettings => HybridCLRGlobalSettings.Instance;
|
public static HybridCLRSettings HybridCLRSettings => HybridCLRSettings.Instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.focus-creative-games.hybridclr_unity",
|
"name": "com.focus-creative-games.hybridclr_unity",
|
||||||
"version": "0.3.7",
|
"version": "0.3.8",
|
||||||
"displayName": "HybridCLR",
|
"displayName": "HybridCLR",
|
||||||
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
|
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
|
||||||
"category": "Runtime",
|
"category": "Runtime",
|
||||||
|
|
Loading…
Reference in New Issue