Tri-Inspector/Editor/TriEditor.cs

76 lines
1.8 KiB
C#
Raw Normal View History

2021-12-07 18:20:36 +03:00
using TriInspector.Utilities;
using UnityEditor;
2022-01-08 20:45:11 +03:00
using UnityEngine;
2021-12-07 18:20:36 +03:00
using UnityEngine.Profiling;
namespace TriInspector
{
public abstract class TriEditor : Editor
{
private TriPropertyTree _inspector;
private void OnEnable()
{
2022-01-08 20:45:11 +03:00
var mode = TriEditorMode.None;
var isInlineEditor = TriGuiHelper.PushedEditorCount > 0;
if (isInlineEditor)
{
mode |= TriEditorMode.InlineEditor;
}
2021-12-07 18:20:36 +03:00
if (serializedObject.targetObject != null)
{
2022-01-08 20:45:11 +03:00
_inspector = TriPropertyTree.Create(serializedObject, mode);
2021-12-07 18:20:36 +03:00
}
}
private void OnDisable()
{
_inspector?.Destroy();
2022-01-08 20:45:11 +03:00
_inspector = null;
2021-12-07 18:20:36 +03:00
}
public override void OnInspectorGUI()
{
if (_inspector == null)
{
DrawDefaultInspector();
return;
}
serializedObject.UpdateIfRequiredOrScript();
2022-01-05 16:11:51 +03:00
Profiler.BeginSample("TriInspector.Update()");
try
2021-12-07 18:20:36 +03:00
{
2022-01-05 16:11:51 +03:00
_inspector.Update();
2021-12-07 18:20:36 +03:00
}
2022-01-05 16:11:51 +03:00
finally
2021-12-07 18:20:36 +03:00
{
2022-01-05 16:11:51 +03:00
Profiler.EndSample();
2021-12-07 18:20:36 +03:00
}
2022-01-05 16:11:51 +03:00
TriGuiHelper.PushEditor(this);
Profiler.BeginSample("TriInspector.DoLayout()");
try
2021-12-07 18:20:36 +03:00
{
2022-01-05 16:11:51 +03:00
_inspector.DoLayout();
2021-12-07 18:20:36 +03:00
}
2022-01-05 16:11:51 +03:00
finally
2021-12-07 18:20:36 +03:00
{
2022-01-05 16:11:51 +03:00
Profiler.EndSample();
TriGuiHelper.PopEditor(this);
2021-12-07 18:20:36 +03:00
}
2022-01-05 16:11:51 +03:00
serializedObject.ApplyModifiedProperties();
2022-01-08 20:45:11 +03:00
if (_inspector.RepaintRequired)
{
_inspector.RepaintRequired = false;
Repaint();
}
2021-12-07 18:20:36 +03:00
}
}
}