mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Rework editors (Fix #114)
This commit is contained in:
parent
04ad48abec
commit
3908308611
78
Editor/Editors/TriEditor.cs
Normal file
78
Editor/Editors/TriEditor.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using TriInspector.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TriInspector.Editors
|
||||
{
|
||||
public abstract class TriEditor : Editor
|
||||
{
|
||||
private TriPropertyTreeForSerializedObject _inspector;
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
OnDisable(this, ref _inspector);
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
OnInspectorGUI(this, ref _inspector);
|
||||
}
|
||||
|
||||
public static void OnDisable(Editor editor, ref TriPropertyTreeForSerializedObject inspector)
|
||||
{
|
||||
inspector?.Dispose();
|
||||
inspector = null;
|
||||
}
|
||||
|
||||
public static void OnInspectorGUI(Editor editor,
|
||||
ref TriPropertyTreeForSerializedObject inspector)
|
||||
{
|
||||
var serializedObject = editor.serializedObject;
|
||||
|
||||
if (serializedObject.targetObjects.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (serializedObject.targetObject == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var targetObject in serializedObject.targetObjects)
|
||||
{
|
||||
if (TriGuiHelper.IsEditorTargetPushed(targetObject))
|
||||
{
|
||||
GUILayout.Label("Recursive inline editors not supported");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (inspector == null)
|
||||
{
|
||||
inspector = new TriPropertyTreeForSerializedObject(serializedObject);
|
||||
}
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
inspector.Update();
|
||||
inspector.RunValidationIfRequired();
|
||||
|
||||
using (TriGuiHelper.PushEditorTarget(serializedObject.targetObject))
|
||||
{
|
||||
inspector.Draw();
|
||||
}
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
inspector.RequestValidation();
|
||||
}
|
||||
|
||||
if (inspector.RepaintRequired)
|
||||
{
|
||||
editor.Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Editor/Editors/TriMonoBehaviourEditor.cs
Normal file
11
Editor/Editors/TriMonoBehaviourEditor.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TriInspector.Editors
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(MonoBehaviour), editorForChildClasses: true, isFallback = true)]
|
||||
internal sealed class TriMonoBehaviourEditor : TriEditor
|
||||
{
|
||||
}
|
||||
}
|
3
Editor/Editors/TriMonoBehaviourEditor.cs.meta
Normal file
3
Editor/Editors/TriMonoBehaviourEditor.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebc893dd0ca44a789a00c03f7a71dc56
|
||||
timeCreated: 1683784191
|
11
Editor/Editors/TriScriptableObjectEditor.cs
Normal file
11
Editor/Editors/TriScriptableObjectEditor.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TriInspector.Editors
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(ScriptableObject), editorForChildClasses: true, isFallback = true)]
|
||||
internal sealed class TriScriptableObjectEditor : TriEditor
|
||||
{
|
||||
}
|
||||
}
|
3
Editor/Editors/TriScriptableObjectEditor.cs.meta
Normal file
3
Editor/Editors/TriScriptableObjectEditor.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fe6a72a9e734fcc8ab5f29cd13c9d53
|
||||
timeCreated: 1683784197
|
32
Editor/Editors/TriScriptedImporterEditor.cs
Normal file
32
Editor/Editors/TriScriptedImporterEditor.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using TriInspectorUnityInternalBridge;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AssetImporters;
|
||||
|
||||
namespace TriInspector.Editors
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(ScriptedImporter), editorForChildClasses: true)]
|
||||
public sealed class TriScriptedImporterEditor : ScriptedImporterEditor
|
||||
{
|
||||
private TriPropertyTreeForSerializedObject _inspector;
|
||||
|
||||
public override void OnDisable()
|
||||
{
|
||||
TriEditor.OnDisable(this, ref _inspector);
|
||||
|
||||
base.OnDisable();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
TriEditor.OnInspectorGUI(this, ref _inspector);
|
||||
|
||||
if (extraDataType != null)
|
||||
{
|
||||
EditorProxy.DoDrawDefaultInspector(extraDataSerializedObject);
|
||||
}
|
||||
|
||||
ApplyRevertGUI();
|
||||
}
|
||||
}
|
||||
}
|
3
Editor/Editors/TriScriptedImporterEditor.cs.meta
Normal file
3
Editor/Editors/TriScriptedImporterEditor.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 421d7c27350d45308b6a91b76560bb50
|
||||
timeCreated: 1683784201
|
@ -1,195 +0,0 @@
|
||||
using TriInspector.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AssetImporters;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(MonoBehaviour), editorForChildClasses: true, isFallback = true)]
|
||||
internal sealed class TriMonoBehaviourEditor : TriEditor
|
||||
{
|
||||
}
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(ScriptableObject), editorForChildClasses: true, isFallback = true)]
|
||||
internal sealed class TriScriptableObjectEditor : TriEditor
|
||||
{
|
||||
}
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(AssetImporter), editorForChildClasses: true)]
|
||||
public sealed class TriAssetImporterEditor : AssetImporterEditor
|
||||
{
|
||||
private TriPropertyTreeForSerializedObject _inspector;
|
||||
|
||||
public override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_inspector?.Dispose();
|
||||
_inspector = null;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (serializedObject.targetObjects.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (serializedObject.targetObject == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TriGuiHelper.IsEditorTargetPushed(serializedObject.targetObject))
|
||||
{
|
||||
GUILayout.Label("Recursive inline editors not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inspector == null)
|
||||
{
|
||||
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
|
||||
}
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
_inspector.Update();
|
||||
_inspector.RunValidationIfRequired();
|
||||
|
||||
using (TriGuiHelper.PushEditorTarget(target))
|
||||
{
|
||||
_inspector.Draw();
|
||||
ApplyRevertGUI();
|
||||
}
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
_inspector.RequestValidation();
|
||||
}
|
||||
|
||||
if (_inspector.RepaintRequired)
|
||||
{
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(ScriptedImporter), editorForChildClasses: true)]
|
||||
public sealed class TriScriptedImporterEditor : ScriptedImporterEditor
|
||||
{
|
||||
private TriPropertyTreeForSerializedObject _inspector;
|
||||
|
||||
public override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_inspector?.Dispose();
|
||||
_inspector = null;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (serializedObject.targetObjects.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (serializedObject.targetObject == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TriGuiHelper.IsEditorTargetPushed(serializedObject.targetObject))
|
||||
{
|
||||
GUILayout.Label("Recursive inline editors not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inspector == null)
|
||||
{
|
||||
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
|
||||
}
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
_inspector.Update();
|
||||
_inspector.RunValidationIfRequired();
|
||||
|
||||
using (TriGuiHelper.PushEditorTarget(target))
|
||||
{
|
||||
_inspector.Draw();
|
||||
ApplyRevertGUI();
|
||||
}
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
_inspector.RequestValidation();
|
||||
}
|
||||
|
||||
if (_inspector.RepaintRequired)
|
||||
{
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TriEditor : Editor
|
||||
{
|
||||
private TriPropertyTreeForSerializedObject _inspector;
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_inspector?.Dispose();
|
||||
_inspector = null;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (serializedObject.targetObjects.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (serializedObject.targetObject == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TriGuiHelper.IsEditorTargetPushed(serializedObject.targetObject))
|
||||
{
|
||||
GUILayout.Label("Recursive inline editors not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inspector == null)
|
||||
{
|
||||
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
|
||||
}
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
_inspector.Update();
|
||||
_inspector.RunValidationIfRequired();
|
||||
|
||||
using (TriGuiHelper.PushEditorTarget(target))
|
||||
{
|
||||
_inspector.Draw();
|
||||
}
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
_inspector.RequestValidation();
|
||||
}
|
||||
|
||||
if (_inspector.RepaintRequired)
|
||||
{
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
Unity.InternalAPIEditorBridge.012/EditorProxy.cs
Normal file
12
Unity.InternalAPIEditorBridge.012/EditorProxy.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace TriInspectorUnityInternalBridge
|
||||
{
|
||||
internal static class EditorProxy
|
||||
{
|
||||
public static void DoDrawDefaultInspector(SerializedObject obj)
|
||||
{
|
||||
Editor.DoDrawDefaultInspector(obj);
|
||||
}
|
||||
}
|
||||
}
|
3
Unity.InternalAPIEditorBridge.012/EditorProxy.cs.meta
Normal file
3
Unity.InternalAPIEditorBridge.012/EditorProxy.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 993f9dfd66614ba68fcf95c0e7e098e3
|
||||
timeCreated: 1683783433
|
Loading…
Reference in New Issue
Block a user