Last active
February 3, 2020 11:23
-
-
Save RyanNielson/bd735c0b23e1a36d0faf96b83fd74afb to your computer and use it in GitHub Desktop.
A custom Inspector for Unity's Transform component to make it nicer when working on 2D games.
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
using UnityEngine; | |
using UnityEditor; | |
[CanEditMultipleObjects, CustomEditor(typeof(Transform))] | |
public class TransformEditor2D : Editor | |
{ | |
public override void OnInspectorGUI() | |
{ | |
Transform transform = (Transform)target; | |
Vector3 position = EditorGUILayout.Vector2Field("Position", transform.localPosition); | |
Vector3 rotation = new Vector3(0, 0, EditorGUILayout.FloatField("Rotation", transform.localEulerAngles.z)); | |
Vector3 scale = EditorGUILayout.Vector2Field("Scale", transform.localScale); | |
if (GUI.changed) | |
{ | |
Undo.RecordObject(transform, "Transform Changed"); | |
transform.localPosition = position; | |
transform.localEulerAngles = rotation; | |
transform.localScale = scale; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment