[fix] 修复 SettingsProvider 卡编辑器的问题 (#16)
* [change] 跨版本兼容问题优化,菜单新增文档 1. 添加 EditorStatusWatcher 解决 git 等外部修改了配置不能同步的问题。 2. Reset 按钮 icon 2021版本有区别,同步之 * [fix] 解决 SettingProviders 卡编辑器的问题main
parent
bf8e5c4840
commit
3918b707e3
|
@ -13,9 +13,6 @@ public static class EditorStatusWatcher
|
|||
static bool isFocused;
|
||||
static EditorStatusWatcher() => EditorApplication.update += Update;
|
||||
static void Update()
|
||||
{
|
||||
//当编辑器 focus 后如果优先发生编译,则等待其完成编译再刷新内部逻辑(猜想&防御)
|
||||
if (!EditorApplication.isCompiling)
|
||||
{
|
||||
if (isFocused != InternalEditorUtility.isApplicationActive)
|
||||
{
|
||||
|
@ -28,4 +25,3 @@ public static class EditorStatusWatcher
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,14 +2,13 @@ using System;
|
|||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Presets;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
namespace HybridCLR.Editor
|
||||
{
|
||||
public class HybridCLRSettingsProvider : SettingsProvider
|
||||
{
|
||||
private static SerializedObject _serializedObject;
|
||||
private SerializedObject _serializedObject;
|
||||
private SerializedProperty _enable;
|
||||
private SerializedProperty _useGlobalIl2cpp;
|
||||
private SerializedProperty _cloneFromGitee;
|
||||
|
@ -29,9 +28,13 @@ namespace HybridCLR.Editor
|
|||
public override void OnActivate(string searchContext, VisualElement rootElement)
|
||||
{
|
||||
EditorStatusWatcher.OnEditorFocused += OnEditorFocused;
|
||||
HybridCLRSettings.Instance.Save();
|
||||
var setting = HybridCLRSettings.Instance;
|
||||
_serializedObject = _serializedObject ?? new SerializedObject(setting);
|
||||
InitGUI();
|
||||
}
|
||||
private void InitGUI()
|
||||
{
|
||||
var setting = HybridCLRSettings.LoadOrCreate();
|
||||
_serializedObject?.Dispose();
|
||||
_serializedObject = new SerializedObject(setting);
|
||||
_enable = _serializedObject.FindProperty("enable");
|
||||
_useGlobalIl2cpp = _serializedObject.FindProperty("useGlobalIl2cpp");
|
||||
_cloneFromGitee = _serializedObject.FindProperty("cloneFromGitee");
|
||||
|
@ -47,13 +50,11 @@ namespace HybridCLR.Editor
|
|||
_maxGenericReferenceIteration = _serializedObject.FindProperty("maxGenericReferenceIteration");
|
||||
_maxMethodBridgeGenericIteration = _serializedObject.FindProperty("maxMethodBridgeGenericIteration");
|
||||
}
|
||||
|
||||
private void OnEditorFocused()
|
||||
{
|
||||
_serializedObject = new SerializedObject(HybridCLRSettings.Instance);
|
||||
SettingsService.NotifySettingsProviderChanged();
|
||||
InitGUI();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
public override void OnTitleBarGUI()
|
||||
{
|
||||
base.OnTitleBarGUI();
|
||||
|
@ -104,7 +105,7 @@ namespace HybridCLR.Editor
|
|||
var json = EditorJsonUtility.ToJson(dv);
|
||||
UnityEngine.Object.DestroyImmediate(dv);
|
||||
EditorJsonUtility.FromJsonOverwrite(json, HybridCLRSettings.Instance);
|
||||
HybridCLRSettings.Instance.Save();
|
||||
HybridCLRSettings.Save();
|
||||
});
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
@ -114,11 +115,6 @@ namespace HybridCLR.Editor
|
|||
{
|
||||
using (CreateSettingsWindowGUIScope())
|
||||
{
|
||||
//防止配置文件意外删除
|
||||
if (_serializedObject == null || !_serializedObject.targetObject)
|
||||
{
|
||||
_serializedObject = new SerializedObject(HybridCLRSettings.Instance);
|
||||
}
|
||||
_serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(_enable);
|
||||
|
@ -138,7 +134,7 @@ namespace HybridCLR.Editor
|
|||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
_serializedObject.ApplyModifiedProperties();
|
||||
HybridCLRSettings.Instance.Save();
|
||||
HybridCLRSettings.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,21 +148,22 @@ namespace HybridCLR.Editor
|
|||
{
|
||||
base.OnDeactivate();
|
||||
EditorStatusWatcher.OnEditorFocused -= OnEditorFocused;
|
||||
HybridCLRSettings.Instance.Save();
|
||||
_serializedObject = null;
|
||||
HybridCLRSettings.Save();
|
||||
}
|
||||
|
||||
static HybridCLRSettingsProvider provider;
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateMyCustomSettingsProvider()
|
||||
{
|
||||
if (HybridCLRSettings.Instance)
|
||||
if (HybridCLRSettings.Instance && provider == null)
|
||||
{
|
||||
var provider = new HybridCLRSettingsProvider
|
||||
provider = new HybridCLRSettingsProvider();
|
||||
using (var so = new SerializedObject(HybridCLRSettings.Instance))
|
||||
{
|
||||
keywords = GetSearchKeywordsFromSerializedObject(_serializedObject = _serializedObject ?? new SerializedObject(HybridCLRSettings.Instance))
|
||||
};
|
||||
provider.keywords = GetSearchKeywordsFromSerializedObject(so);
|
||||
}
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ namespace HybridCLR.Editor
|
|||
return s_Instance;
|
||||
}
|
||||
}
|
||||
public static void LoadOrCreate()
|
||||
public static T LoadOrCreate()
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
|
@ -33,9 +33,10 @@ namespace HybridCLR.Editor
|
|||
{
|
||||
Debug.LogError($"{nameof(ScriptableSingleton<T>)}: 请指定单例存档路径! ");
|
||||
}
|
||||
return s_Instance;
|
||||
}
|
||||
|
||||
public void Save(bool saveAsText = true)
|
||||
public static void Save(bool saveAsText = true)
|
||||
{
|
||||
if (!s_Instance)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue