Skip to content

Instantly share code, notes, and snippets.

@RyanNielson
Last active February 3, 2020 11:23
Show Gist options
  • Save RyanNielson/bd735c0b23e1a36d0faf96b83fd74afb to your computer and use it in GitHub Desktop.
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.
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