Tri-Inspector/Editor/TriEditor.cs

62 lines
1.5 KiB
C#
Raw Normal View History

using TriInspector.Utilities;
2021-12-07 10:20:36 -05:00
using UnityEditor;
2022-01-08 12:45:11 -05:00
using UnityEngine;
2021-12-07 10:20:36 -05:00
namespace TriInspector
{
2022-05-25 03:10:21 -04:00
[CanEditMultipleObjects]
[CustomEditor(typeof(Object), editorForChildClasses: true, isFallback = true)]
public class TriEditor : Editor
2021-12-07 10:20:36 -05:00
{
private TriPropertyTreeForSerializedObject _inspector;
2021-12-07 10:20:36 -05:00
private void OnDisable()
{
2022-05-17 06:33:23 -04:00
_inspector?.Dispose();
2022-01-08 12:45:11 -05:00
_inspector = null;
2021-12-07 10:20:36 -05:00
}
public override void OnInspectorGUI()
{
if (_inspector == null)
{
2022-05-18 14:29:06 -04:00
if (serializedObject.targetObjects.Length == 0)
{
return;
}
if (serializedObject.targetObject == null)
{
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
return;
}
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
2021-12-07 10:20:36 -05:00
}
serializedObject.UpdateIfRequiredOrScript();
2022-06-03 06:59:16 -04:00
_inspector.Update();
2022-01-20 05:06:04 -05:00
2022-06-03 06:59:16 -04:00
if (_inspector.ValidationRequired)
2022-01-15 11:25:12 -05:00
{
2022-06-03 06:59:16 -04:00
_inspector.RunValidation();
2022-01-15 11:25:12 -05:00
}
2021-12-07 10:20:36 -05:00
2022-06-03 06:59:16 -04:00
using (TriGuiHelper.PushEditorTarget(target))
2021-12-07 10:20:36 -05:00
{
2022-06-03 06:59:16 -04:00
_inspector.Draw();
2021-12-07 10:20:36 -05:00
}
2022-01-15 11:25:12 -05:00
if (serializedObject.ApplyModifiedProperties())
{
_inspector.RequestValidation();
}
2022-01-08 12:45:11 -05:00
if (_inspector.RepaintRequired)
{
Repaint();
}
2021-12-07 10:20:36 -05:00
}
}
}