Hi all, I am making some small modifications to the built in Unity inspector for the Transform component. I am aware there is a DrawDefaultInspector() command, however this doesn't draw the default inspector in the same way, it actually looks more like the Debug inspector even when in Normal view mode. So, due to me being a little fastidious with how my things look, I set about just coding the same inspector look into my editor script. However when getting to the rotation, I've noticed it glitches. Sometimes in a static scene when I have just selected an object, I will see the rotation change slightly over time. In addition when using the option to adjust the rotation with the inspector, by click-dragging over one of the axis, the model flips about and generally freaks out, instead of rotating smoothly as with the normal inspector. Scale/Position work fine, so I guess it's something to do with how I set the rotation? I also can't seem to set the rotation, for example if I enter 0 in an axis, it will sometimes snap back to something like 0.006835938 or 3.2 (oddly). If someone could take a look and let me know how I could better this. I admit I don't actually know -what- the problem is, I was hoping to look at how Unity does it's inspector but that's obviously not possible, such a small thing and it's sucking up hours. :> Thanks! Digitalos The following code: Code (csharp): using UnityEngine; using UnityEditor; [CustomEditor( typeof( Transform ) )] public class InspectorEnhancements : Editor { string transText = ""; Vector3 transPos; Vector3 transRot; Vector3 transScale; Transform currentTarget; void Awake() { currentTarget = (Transform)target; transPos = currentTarget.position; transRot = currentTarget.localEulerAngles; transScale = currentTarget.lossyScale; } public override void OnInspectorGUI() { transPos = EditorGUILayout.Vector3Field( "Position", currentTarget.localPosition ); if( GUILayout.Button( "Copy To Clipboard" ) ) { transText = transPos.ToString(); transText = transText.Replace( "(", "" ); transText = transText.Replace( ")", "" ); EditorGUIUtility.systemCopyBuffer = transText; } transRot = currentTarget.localEulerAngles; // Wrap transRot.x = Mathf.Repeat( transRot.x, 360f ); transRot.y = Mathf.Repeat( transRot.y, 360f ); transRot.z = Mathf.Repeat( transRot.z, 360f ); transRot = EditorGUILayout.Vector3Field( "Rotation", transRot ); transScale = EditorGUILayout.Vector3Field( "Scale", currentTarget.localScale ); currentTarget.localPosition = transPos; currentTarget.localRotation = Quaternion.Euler( transRot ); currentTarget.localScale = transScale; } }
Oddly, I've just noticed only the X axis click-drag method causes it to glitch. Though the errors still seem prone when trying to specify set values, such as 10, or 0, or something or even when I click Reset Rotation, sometimes it resets with non 0 values.