Created
November 14, 2012 16:50
-
-
Save cubed2d/4073256 to your computer and use it in GitHub Desktop.
Transform2DInspector.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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