Guest User

Untitled

a guest
Apr 25th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. [CanEditMultipleObjects]
  5. [CustomEditor(typeof(Transform), true)]
  6. public class NewTransformInspector : Editor
  7. {
  8.     /// <summary>
  9.     /// Draw the inspector widget.
  10.     /// </summary>
  11.     public override void OnInspectorGUI ()
  12.     {
  13.         Transform t = (Transform)target;
  14.  
  15.         float oldLabelWidth = EditorGUIUtility.labelWidth;
  16.         EditorGUIUtility.labelWidth = 15;
  17.  
  18.         EditorGUILayout.BeginHorizontal();
  19.         bool resetPos = GUILayout.Button("P", GUILayout.Width(20f));
  20.         Vector3 position = EditorGUILayout.Vector3Field("", t.localPosition);
  21.         EditorGUILayout.EndHorizontal();
  22.  
  23.         EditorGUILayout.BeginHorizontal();
  24.         bool resetRot = GUILayout.Button("R", GUILayout.Width(20f));
  25.         Vector3 eulerAngles = EditorGUILayout.Vector3Field("", t.localEulerAngles);
  26.         EditorGUILayout.EndHorizontal();
  27.  
  28.         EditorGUILayout.BeginHorizontal();
  29.         bool resetScale = GUILayout.Button("S", GUILayout.Width(20f));
  30.         Vector3 scale = EditorGUILayout.Vector3Field("", t.localScale);
  31.         EditorGUILayout.EndHorizontal();
  32.  
  33.         EditorGUIUtility.labelWidth = oldLabelWidth;
  34.  
  35.         if (resetPos) position = Vector3.zero;
  36.         if (resetRot) eulerAngles = Vector3.zero;
  37.         if (resetScale) scale = Vector3.one;
  38.  
  39.         if (GUI.changed)
  40.         {
  41.             Undo.RecordObject(t, "Transform Change");
  42.  
  43.             t.localPosition = FixIfNaN(position);
  44.             t.localEulerAngles = FixIfNaN(eulerAngles);
  45.             t.localScale = FixIfNaN(scale);
  46.         }
  47.     }
  48.  
  49.     private Vector3 FixIfNaN(Vector3 v)
  50.     {
  51.         if (float.IsNaN(v.x))
  52.         {
  53.             v.x = 0;
  54.         }
  55.         if (float.IsNaN(v.y))
  56.         {
  57.             v.y = 0;
  58.         }
  59.         if (float.IsNaN(v.z))
  60.         {
  61.             v.z = 0;
  62.         }
  63.         return v;
  64.     }
  65.  
  66. }
Add Comment
Please, Sign In to add comment