TransformInspector

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: ==Description== '''TransformInspector.cs''' is a reverse engineered version of Unity's built-in ''UnityEditor.TransformInspector'' class. It should both look and function exactly as the or...)
 
(Description)
Line 3: Line 3:
  
 
This is currently a much better alternative to using Editor.DrawDefaultInspector in your custom Transform inspector class since DrawDefaultInspector does not preserve the inspector's unique GUI layout.
 
This is currently a much better alternative to using Editor.DrawDefaultInspector in your custom Transform inspector class since DrawDefaultInspector does not preserve the inspector's unique GUI layout.
 +
 +
While the first code provided is apparently an exact match of Unity's original, the firstSet variable does not actually appear to do anything at all. Therefore a cut-down version is also listed below.
  
 
==Usage==
 
==Usage==

Revision as of 17:00, 5 March 2011

Description

TransformInspector.cs is a reverse engineered version of Unity's built-in UnityEditor.TransformInspector class. It should both look and function exactly as the original, bugs and all. Once loaded into your project, all Transform components will be routed through TransformInspector.cs allowing you to easily extend or modify the inspector.

This is currently a much better alternative to using Editor.DrawDefaultInspector in your custom Transform inspector class since DrawDefaultInspector does not preserve the inspector's unique GUI layout.

While the first code provided is apparently an exact match of Unity's original, the firstSet variable does not actually appear to do anything at all. Therefore a cut-down version is also listed below.

Usage

Place TransformInspector.cs into an Editor folder inside of your project's Assets folder.

TransformInspector.cs

<csharp>// Reverse engineered UnityEditor.TransformInspector

using UnityEngine; using UnityEditor; using System.Collections;

[CustomEditor(typeof(Transform))] public class TransformInspector : Editor {

private bool firstSet; private Vector3 rotation; private Quaternion oldQuaternion;


public TransformInspector () { this.firstSet = true; }


public override void OnInspectorGUI () { EditorGUIUtility.LookLikeControls(); Transform t = (Transform)this.target; EditorGUI.indentLevel = 0; if (!this.firstSet) { if (this.oldQuaternion != t.localRotation) { this.firstSet = false; this.rotation = t.localEulerAngles; this.oldQuaternion = t.localRotation; } } Vector3 position = EditorGUILayout.Vector3Field("Position", t.localPosition); this.rotation = EditorGUILayout.Vector3Field("Rotation", this.rotation); Vector3 scale = EditorGUILayout.Vector3Field("Scale", t.localScale); if (GUI.changed) { Undo.RegisterUndo(t, "Transform Change"); this.rotation = this.FixIfNaN(this.rotation); t.localPosition = this.FixIfNaN(position); t.localEulerAngles = this.rotation; this.oldQuaternion = t.localRotation; t.localScale = this.FixIfNaN(scale); } EditorGUIUtility.LookLikeInspector(); }


private Vector3 FixIfNaN (Vector3 v) { if (float.IsNaN(v.x)) { v.x = 0; } if (float.IsNaN(v.y)) { v.y = 0; } if (float.IsNaN(v.z)) { v.z = 0; } return v; }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox