diff --git a/Assets/BetterProjectSettings/Editor/SettingTools/DefaultProjectSettingsProvider.cs b/Assets/BetterProjectSettings/Editor/SettingTools/DefaultProjectSettingsProvider.cs index fe205bc..11aacdd 100644 --- a/Assets/BetterProjectSettings/Editor/SettingTools/DefaultProjectSettingsProvider.cs +++ b/Assets/BetterProjectSettings/Editor/SettingTools/DefaultProjectSettingsProvider.cs @@ -1,5 +1,7 @@ using Better.ProjectSettings.Runtime; using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine.UIElements; namespace Better.ProjectSettings.EditorAddons { @@ -12,9 +14,9 @@ protected DefaultProjectSettingsProvider(string path, SettingsScope scopes = Set _editor = Editor.CreateEditor(_settings); } - protected override void DrawGUI() + protected override void CreateVisualElements(VisualElement rootElement) { - _editor.OnInspectorGUI(); + InspectorElement.FillDefaultInspector(rootElement, _settingsObject, _editor); } } } \ No newline at end of file diff --git a/Assets/BetterProjectSettings/Editor/SettingTools/ProjectSettingsProvider.cs b/Assets/BetterProjectSettings/Editor/SettingTools/ProjectSettingsProvider.cs index 6749c16..c5bbd7f 100644 --- a/Assets/BetterProjectSettings/Editor/SettingTools/ProjectSettingsProvider.cs +++ b/Assets/BetterProjectSettings/Editor/SettingTools/ProjectSettingsProvider.cs @@ -1,9 +1,12 @@ using System.IO; +using Better.Commons.Runtime.Extensions; using Better.Internal.Core.Runtime; using Better.ProjectSettings.Runtime; using Better.Singletons.Runtime; using UnityEditor; +using UnityEditor.UIElements; using UnityEngine; +using UnityEngine.UIElements; namespace Better.ProjectSettings.EditorAddons { @@ -11,8 +14,6 @@ public abstract class ProjectSettingsProvider : SettingsProvider where T : Sc { protected readonly T _settings; protected readonly SerializedObject _settingsObject; - private GUIStyle _style; - private const int Space = 8; public const string ProjectPath = PrefixConstants.ProjectPrefix + "/"; protected ProjectSettingsProvider(string path, SettingsScope scope = SettingsScope.Project) @@ -23,29 +24,22 @@ protected ProjectSettingsProvider(string path, SettingsScope scope = SettingsSco label = Path.GetFileName(path); } - public override void OnGUI(string searchContext) + public override void OnActivate(string searchContext, VisualElement rootElement) { - var style = CreateOrGetStyle(); - using (new EditorGUILayout.VerticalScope(style)) - { - DrawGUI(); - } - - _settingsObject.ApplyModifiedPropertiesWithoutUndo(); + CreateVisualElements(rootElement); + rootElement.Bind(_settingsObject); + rootElement.RegisterCallback(OnObjectChanged); } - private GUIStyle CreateOrGetStyle() + protected virtual void OnObjectChanged(SerializedObjectChangeEvent changeEvent) { - if (_style != null) - { - return _style; - } + changeEvent.changedObject.ApplyModifiedPropertiesWithoutUndo(); + } - _style = new GUIStyle(); - _style.margin = new RectOffset(Space, Space, Space, Space); - return _style; + public override void OnDeactivate() + { } - protected abstract void DrawGUI(); + protected abstract void CreateVisualElements(VisualElement rootElement); } } \ No newline at end of file