Skip to content

Instantly share code, notes, and snippets.

@cubed2d
Created November 14, 2012 16:50
Show Gist options
  • Save cubed2d/4073256 to your computer and use it in GitHub Desktop.
Save cubed2d/4073256 to your computer and use it in GitHub Desktop.
Transform2DInspector.cs
[CustomEditor(typeof(Transform))]
public class Transform2DInspector : Editor
{
public override void OnInspectorGUI()
{
// Grab the target transform
Transform transform = (Transform)target;
tk2dBaseSprite sprite = transform.gameObject.GetComponent<tk2dBaseSprite>();
if (sprite != null)
{
// draw a simplified inspector here
if (GUI.changed)
{
Undo.RegisterUndo(new Object[]{transform, sprite}, "Changed Sprite Transform"); // not checked to see if registering for undo also calls SetDirty for us
EditorUtility.SetDirty(sprite); // SetDirty tells unity to save the component we are editing
}
}
else
{
// No sprite, draw the default inspector
// Note, i think there was some problem with falling through to base.OnInspectorGUI(),
// it draws the transform inspector all wrong. you need to recreate the default inspector!
// see this wiki page http://wiki.unity3d.com/index.php?title=TransformInspector
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment