Tri-Inspector/Editor/TriEditor.cs

59 lines
1.3 KiB
C#
Raw Normal View History

2021-12-07 18:20:36 +03:00
using TriInspector.Utilities;
using UnityEditor;
using UnityEngine.Profiling;
namespace TriInspector
{
public abstract class TriEditor : Editor
{
private TriPropertyTree _inspector;
private void OnEnable()
{
if (serializedObject.targetObject != null)
{
_inspector = TriPropertyTree.Create(serializedObject);
}
}
private void OnDisable()
{
_inspector?.Destroy();
}
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();
2021-12-07 18:20:36 +03:00
}
}
}