2022-10-09 03:25:56 +08:00
|
|
|
using System;
|
|
|
|
using System.Reflection;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEditor.Presets;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace HybridCLR.Editor
|
|
|
|
{
|
|
|
|
public class HybridCLRSettingsProvider : SettingsProvider
|
|
|
|
{
|
2022-11-02 10:17:41 +08:00
|
|
|
private SerializedObject _serializedObject;
|
2022-10-18 13:51:38 +08:00
|
|
|
private SerializedProperty _enable;
|
|
|
|
private SerializedProperty _useGlobalIl2cpp;
|
2022-11-28 12:20:52 +08:00
|
|
|
private SerializedProperty _hybridclrRepoURL;
|
|
|
|
private SerializedProperty _il2cppPlusRepoURL;
|
2022-10-18 13:51:38 +08:00
|
|
|
private SerializedProperty _hotUpdateAssemblyDefinitions;
|
|
|
|
private SerializedProperty _hotUpdateAssemblies;
|
|
|
|
private SerializedProperty _preserveHotUpdateAssemblies;
|
2022-10-23 17:46:09 +08:00
|
|
|
private SerializedProperty _hotUpdateDllCompileOutputRootDir;
|
|
|
|
private SerializedProperty _strippedAOTDllOutputRootDir;
|
2022-10-19 11:57:53 +08:00
|
|
|
private SerializedProperty _patchAOTAssemblies;
|
2022-11-05 22:22:39 +08:00
|
|
|
private SerializedProperty _differentialHybridAssemblies;
|
|
|
|
private SerializedProperty _differentialHybridOptionOutputDir;
|
2022-10-18 13:51:38 +08:00
|
|
|
private SerializedProperty _collectAssetReferenceTypes;
|
|
|
|
private SerializedProperty _outputLinkFile;
|
|
|
|
private SerializedProperty _outputAOTGenericReferenceFile;
|
|
|
|
private SerializedProperty _maxGenericReferenceIteration;
|
|
|
|
private SerializedProperty _maxMethodBridgeGenericIteration;
|
2022-10-09 03:25:56 +08:00
|
|
|
private GUIStyle buttonStyle;
|
|
|
|
public HybridCLRSettingsProvider() : base("Project/HybridCLR Settings", SettingsScope.Project) { }
|
|
|
|
public override void OnActivate(string searchContext, VisualElement rootElement)
|
|
|
|
{
|
2022-10-25 17:36:32 +08:00
|
|
|
EditorStatusWatcher.OnEditorFocused += OnEditorFocused;
|
2022-11-02 10:17:41 +08:00
|
|
|
InitGUI();
|
|
|
|
}
|
|
|
|
private void InitGUI()
|
|
|
|
{
|
|
|
|
var setting = HybridCLRSettings.LoadOrCreate();
|
|
|
|
_serializedObject?.Dispose();
|
|
|
|
_serializedObject = new SerializedObject(setting);
|
2022-10-18 13:51:38 +08:00
|
|
|
_enable = _serializedObject.FindProperty("enable");
|
|
|
|
_useGlobalIl2cpp = _serializedObject.FindProperty("useGlobalIl2cpp");
|
2022-11-28 12:20:52 +08:00
|
|
|
_hybridclrRepoURL = _serializedObject.FindProperty("hybridclrRepoURL");
|
|
|
|
_il2cppPlusRepoURL = _serializedObject.FindProperty("il2cppPlusRepoURL");
|
2022-10-18 13:51:38 +08:00
|
|
|
_hotUpdateAssemblyDefinitions = _serializedObject.FindProperty("hotUpdateAssemblyDefinitions");
|
|
|
|
_hotUpdateAssemblies = _serializedObject.FindProperty("hotUpdateAssemblies");
|
|
|
|
_preserveHotUpdateAssemblies = _serializedObject.FindProperty("preserveHotUpdateAssemblies");
|
2022-10-23 17:46:09 +08:00
|
|
|
_hotUpdateDllCompileOutputRootDir = _serializedObject.FindProperty("hotUpdateDllCompileOutputRootDir");
|
|
|
|
_strippedAOTDllOutputRootDir = _serializedObject.FindProperty("strippedAOTDllOutputRootDir");
|
2022-10-19 11:57:53 +08:00
|
|
|
_patchAOTAssemblies = _serializedObject.FindProperty("patchAOTAssemblies");
|
2022-11-05 22:22:39 +08:00
|
|
|
_differentialHybridAssemblies = _serializedObject.FindProperty("differentialHybridAssemblies");
|
|
|
|
_differentialHybridOptionOutputDir = _serializedObject.FindProperty("differentialHybridOptionOutputDir");
|
2022-10-18 13:51:38 +08:00
|
|
|
_collectAssetReferenceTypes = _serializedObject.FindProperty("collectAssetReferenceTypes");
|
|
|
|
_outputLinkFile = _serializedObject.FindProperty("outputLinkFile");
|
|
|
|
_outputAOTGenericReferenceFile = _serializedObject.FindProperty("outputAOTGenericReferenceFile");
|
|
|
|
_maxGenericReferenceIteration = _serializedObject.FindProperty("maxGenericReferenceIteration");
|
|
|
|
_maxMethodBridgeGenericIteration = _serializedObject.FindProperty("maxMethodBridgeGenericIteration");
|
2022-10-09 03:25:56 +08:00
|
|
|
}
|
2022-10-25 17:36:32 +08:00
|
|
|
private void OnEditorFocused()
|
|
|
|
{
|
2022-11-02 10:17:41 +08:00
|
|
|
InitGUI();
|
|
|
|
Repaint();
|
2022-10-25 17:36:32 +08:00
|
|
|
}
|
2022-10-09 03:25:56 +08:00
|
|
|
public override void OnTitleBarGUI()
|
|
|
|
{
|
|
|
|
base.OnTitleBarGUI();
|
|
|
|
var rect = GUILayoutUtility.GetLastRect();
|
2022-10-09 21:08:53 +08:00
|
|
|
buttonStyle = buttonStyle ?? GUI.skin.GetStyle("IconButton");
|
2022-10-09 03:25:56 +08:00
|
|
|
|
|
|
|
#region 绘制官方网站跳转按钮
|
|
|
|
var w = rect.x + rect.width;
|
2022-10-25 17:36:32 +08:00
|
|
|
rect.x = w - 57;
|
2022-10-09 03:25:56 +08:00
|
|
|
rect.y += 6;
|
|
|
|
rect.width = rect.height = 18;
|
|
|
|
var content = EditorGUIUtility.IconContent("_Help");
|
|
|
|
content.tooltip = "点击访问 HybridCLR 官方文档";
|
|
|
|
if (GUI.Button(rect, content, buttonStyle))
|
|
|
|
{
|
|
|
|
Application.OpenURL("https://focus-creative-games.github.io/hybridclr/");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 绘制 Preset
|
|
|
|
rect.x += 19;
|
|
|
|
content = EditorGUIUtility.IconContent("Preset.Context");
|
|
|
|
content.tooltip = "点击存储或加载 Preset .";
|
|
|
|
if (GUI.Button(rect, content, buttonStyle))
|
|
|
|
{
|
2022-10-09 20:53:13 +08:00
|
|
|
var target = HybridCLRSettings.Instance;
|
2022-10-09 03:25:56 +08:00
|
|
|
var receiver = ScriptableObject.CreateInstance<SettingsPresetReceiver>();
|
2022-10-25 17:36:32 +08:00
|
|
|
receiver.Init(target, this);
|
2022-10-09 03:25:56 +08:00
|
|
|
PresetSelector.ShowSelector(target, null, true, receiver);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 绘制 Reset
|
|
|
|
rect.x += 19;
|
2022-10-25 17:36:32 +08:00
|
|
|
content = EditorGUIUtility.IconContent(
|
|
|
|
#if UNITY_2021_3_OR_NEWER
|
|
|
|
"pane options"
|
|
|
|
#else
|
|
|
|
"_Popup"
|
|
|
|
#endif
|
|
|
|
);
|
2022-10-09 03:25:56 +08:00
|
|
|
content.tooltip = "Reset";
|
|
|
|
if (GUI.Button(rect, content, buttonStyle))
|
|
|
|
{
|
2022-10-25 17:36:32 +08:00
|
|
|
GenericMenu menu = new GenericMenu();
|
|
|
|
menu.AddItem(new GUIContent("Reset"), false, () =>
|
2022-10-09 03:25:56 +08:00
|
|
|
{
|
2022-10-09 20:53:13 +08:00
|
|
|
Undo.RecordObject(HybridCLRSettings.Instance, "Capture Value for Reset");
|
|
|
|
var dv = ScriptableObject.CreateInstance<HybridCLRSettings>();
|
2022-10-09 03:25:56 +08:00
|
|
|
var json = EditorJsonUtility.ToJson(dv);
|
2022-10-25 17:36:32 +08:00
|
|
|
UnityEngine.Object.DestroyImmediate(dv);
|
|
|
|
EditorJsonUtility.FromJsonOverwrite(json, HybridCLRSettings.Instance);
|
2022-11-02 10:17:41 +08:00
|
|
|
HybridCLRSettings.Save();
|
2022-10-09 03:25:56 +08:00
|
|
|
});
|
2022-10-25 17:36:32 +08:00
|
|
|
menu.ShowAsContext();
|
2022-10-09 03:25:56 +08:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
public override void OnGUI(string searchContext)
|
|
|
|
{
|
|
|
|
using (CreateSettingsWindowGUIScope())
|
|
|
|
{
|
2022-11-02 17:54:46 +08:00
|
|
|
//解决编辑器打包时出现的 _serializedObject.targetObject 意外销毁的情况
|
|
|
|
if (_serializedObject == null||!_serializedObject.targetObject)
|
|
|
|
{
|
|
|
|
InitGUI();
|
|
|
|
}
|
2022-10-18 13:51:38 +08:00
|
|
|
_serializedObject.Update();
|
2022-10-09 03:25:56 +08:00
|
|
|
EditorGUI.BeginChangeCheck();
|
2022-10-18 13:51:38 +08:00
|
|
|
EditorGUILayout.PropertyField(_enable);
|
2022-11-28 12:20:52 +08:00
|
|
|
EditorGUILayout.PropertyField(_hybridclrRepoURL);
|
|
|
|
EditorGUILayout.PropertyField(_il2cppPlusRepoURL);
|
2022-10-18 13:51:38 +08:00
|
|
|
EditorGUILayout.PropertyField(_useGlobalIl2cpp);
|
|
|
|
EditorGUILayout.PropertyField(_hotUpdateAssemblyDefinitions);
|
|
|
|
EditorGUILayout.PropertyField(_hotUpdateAssemblies);
|
|
|
|
EditorGUILayout.PropertyField(_preserveHotUpdateAssemblies);
|
2022-10-23 17:46:09 +08:00
|
|
|
EditorGUILayout.PropertyField(_hotUpdateDllCompileOutputRootDir);
|
|
|
|
EditorGUILayout.PropertyField(_strippedAOTDllOutputRootDir);
|
2022-10-19 11:57:53 +08:00
|
|
|
EditorGUILayout.PropertyField(_patchAOTAssemblies);
|
2022-11-05 22:22:39 +08:00
|
|
|
EditorGUILayout.PropertyField(_differentialHybridAssemblies);
|
|
|
|
EditorGUILayout.PropertyField(_differentialHybridOptionOutputDir);
|
2022-10-18 13:51:38 +08:00
|
|
|
EditorGUILayout.PropertyField(_collectAssetReferenceTypes);
|
|
|
|
EditorGUILayout.PropertyField(_outputLinkFile);
|
|
|
|
EditorGUILayout.PropertyField(_outputAOTGenericReferenceFile);
|
|
|
|
EditorGUILayout.PropertyField(_maxGenericReferenceIteration);
|
|
|
|
EditorGUILayout.PropertyField(_maxMethodBridgeGenericIteration);
|
2022-10-09 03:25:56 +08:00
|
|
|
if (EditorGUI.EndChangeCheck())
|
|
|
|
{
|
2022-10-18 13:51:38 +08:00
|
|
|
_serializedObject.ApplyModifiedProperties();
|
2022-11-02 10:17:41 +08:00
|
|
|
HybridCLRSettings.Save();
|
2022-10-09 03:25:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private IDisposable CreateSettingsWindowGUIScope()
|
|
|
|
{
|
|
|
|
var unityEditorAssembly = Assembly.GetAssembly(typeof(EditorWindow));
|
|
|
|
var type = unityEditorAssembly.GetType("UnityEditor.SettingsWindow+GUIScope");
|
|
|
|
return Activator.CreateInstance(type) as IDisposable;
|
|
|
|
}
|
|
|
|
public override void OnDeactivate()
|
|
|
|
{
|
|
|
|
base.OnDeactivate();
|
2022-10-25 17:36:32 +08:00
|
|
|
EditorStatusWatcher.OnEditorFocused -= OnEditorFocused;
|
2022-11-02 10:17:41 +08:00
|
|
|
HybridCLRSettings.Save();
|
2022-10-09 03:25:56 +08:00
|
|
|
}
|
2022-11-02 10:17:41 +08:00
|
|
|
|
|
|
|
static HybridCLRSettingsProvider provider;
|
2022-10-09 03:25:56 +08:00
|
|
|
[SettingsProvider]
|
|
|
|
public static SettingsProvider CreateMyCustomSettingsProvider()
|
|
|
|
{
|
2022-11-02 10:17:41 +08:00
|
|
|
if (HybridCLRSettings.Instance && provider == null)
|
2022-10-09 03:25:56 +08:00
|
|
|
{
|
2022-11-02 10:17:41 +08:00
|
|
|
provider = new HybridCLRSettingsProvider();
|
|
|
|
using (var so = new SerializedObject(HybridCLRSettings.Instance))
|
2022-10-09 03:25:56 +08:00
|
|
|
{
|
2022-11-02 10:17:41 +08:00
|
|
|
provider.keywords = GetSearchKeywordsFromSerializedObject(so);
|
|
|
|
}
|
2022-10-09 03:25:56 +08:00
|
|
|
}
|
2022-11-02 10:17:41 +08:00
|
|
|
return provider;
|
2022-10-09 03:25:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|