Skip to content

Instantly share code, notes, and snippets.

@Naphier
Last active November 5, 2015 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naphier/3f8fbd682a77d7cbb8ec to your computer and use it in GitHub Desktop.
Save Naphier/3f8fbd682a77d7cbb8ec to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
// This custom Inspector just shows the default inspector and
// then, at the correct time, destroys the component if it has
// been flagged for destruction.
[CustomEditor(typeof(ShowLocalAxis))]
public class ShowLocalAxisInspector : Editor
{
public override void OnInspectorGUI()
{
// Draw the standard inspector.
base.DrawDefaultInspector();
// Get the reference to the ShowLocalAxis component in the inspector.
ShowLocalAxis showRotated = (ShowLocalAxis)target;
// If the CustomTransforInspector class has set the ShowRotated component to be destroyed
// then if the inspector's event state is Repaint it is save to actually destroy the component.
if (showRotated.destroyWhenSafe && Event.current.type == EventType.Repaint)
{
DestroyImmediate(showRotated);
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment