Tri-Inspector/Editor/TriEditor.cs

87 lines
2.2 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
using UnityEngine.Profiling;
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-01-05 08:11:51 -05:00
Profiler.BeginSample("TriInspector.Update()");
try
2021-12-07 10:20:36 -05:00
{
2022-01-05 08:11:51 -05:00
_inspector.Update();
2021-12-07 10:20:36 -05:00
}
2022-01-05 08:11:51 -05:00
finally
2021-12-07 10:20:36 -05:00
{
2022-01-05 08:11:51 -05:00
Profiler.EndSample();
2021-12-07 10:20:36 -05:00
}
2022-01-20 05:06:04 -05:00
2022-01-15 11:25:12 -05:00
Profiler.BeginSample("TriInspector.RunValidation()");
try
{
if (_inspector.ValidationRequired)
{
_inspector.RunValidation();
}
}
finally
{
Profiler.EndSample();
}
2021-12-07 10:20:36 -05:00
2022-01-05 08:11:51 -05:00
Profiler.BeginSample("TriInspector.DoLayout()");
try
2021-12-07 10:20:36 -05:00
{
using (TriGuiHelper.PushEditorTarget(target))
{
_inspector.Draw();
}
2021-12-07 10:20:36 -05:00
}
2022-01-05 08:11:51 -05:00
finally
2021-12-07 10:20:36 -05:00
{
2022-01-05 08:11:51 -05:00
Profiler.EndSample();
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
}
}
}