step-timeline/Scripts/Editor/StepEditor.cs

70 lines
1.9 KiB
C#
Raw Normal View History

using UnityEditor;
using UnityEngine;
using TriInspector.Editors;
using UnityEngine.UIElements;
namespace R0bbie.Timeline
{
/// <summary>
/// Editor class to update the GameObject name based on the shortName of the step and child position
/// </summary>
[CustomEditor(typeof(Step),true)]
public class StepEditor : TriEditor
{
private TriEditorCore _core;
/// <summary>
/// Unity OnEnable function - called here when object is selected to be viewed in inspector
/// </summary>
void OnEnable()
{
Rename();
// Re-implement base TriEditor.OnEnable logic (not overridable sadly as its private)
_core = new TriEditorCore(this);
}
/// <summary>
/// Unity OnDisable function - called here when object selection in inspector view is cleared
/// </summary>
void OnDisable()
{
Rename();
// Re-implement base TriEditor.OnDisable logic
_core.Dispose();
}
/// <summary>
/// Rename the Step GameObject to reflect latest settings
/// </summary>
void Rename()
{
// If the object has been destroyed avoid changing the name
if (!target)
return;
// Get target as Step
Step step = target as Step;
if (!step)
return;
step.UpdateStepName();
}
/// <summary>
/// Function from base TriEditor class which frustratingly we have to re-implement here due to accessibility issues in the base class
/// </summary>
/// <returns></returns>
public override VisualElement CreateInspectorGUI()
{
return _core.CreateVisualElement();
}
}
}