

Next, we have some adjustments to make to get our inspector to work like Unity’s default inspector. Then we simply apply only the changes that have occurred. Once that has finished and when know what if something has changed we now use Undo.RecordObject() to record the state of the object before any change has been made (this allows use to Undo the operation). Then you’ll see three spots where we check for changes with EditorGUI.BeginChangeCheck() and flag our bools if a change has occurred by checking EditorGUI.EndChangeCheck(). First, we set up some bools to flag when a value is changed in the inspector and we store the initial position, rotation, and scale of our transform so that we can make a comparison later. In the StandardTransformInspector() method we have a few things going on. Then we call our new method, StandardTransformInspector(). We override OnInspectorGUI() and immediately cast target (a property of the Editor class) to a Transform type and set _transform. First, we set up a class level Transform (aptly named _transform) to hold the transform of the target (the selected object) so that we can refer to it throughout the class. Some extra explanation beyond the comments as to what’s going on here. If (!Mathf.Approximately(initial.z, changed.z)) If (!Mathf.Approximately(initial.y, changed.y)) If (!Mathf.Approximately(initial.x, changed.x)) Private Vector3 Appl圜hangesOnly(Vector3 toApply, Vector3 initial, Vector3 changed) Item.localScale, initialLocalScale, _transform.localScale) Item.localEulerAngles, initialLocalEuler, _transform.localEulerAngles) Item.localPosition, initialLocalPosition, _transform.localPosition) we need to manually apply transform changes to all selected objects. Since BeginChangeCheck only works on the selected object _transform.localEulerAngles = localEulerAngles _transform.localPosition = localPosition Undo.RecordObject(_transform, _transform.name) If (didPositionChange || didRotationChange || didScaleChange) Vector3 localScale = EditorGUILayout.Vector3Field("Scale", _transform.localScale) Vector3 localEulerAngles = EditorGUILayout.Vector3Field("Euler Rotation", _transform.localEulerAngles) Vector3 localPosition = EditorGUILayout.Vector3Field("Position", _transform.localPosition) Vector3 initialLocalScale = _transform.localScale Vector3 initialLocalEuler = _transform.localEulerAngles Vector3 initialLocalPosition = _transform.localPosition Store current values for checking later 2) This allows us to also record an undo point properly since we're only when you've not actually made a change. 1) Float values are imprecise, so floating point error may cause changes

Private void StandardTransformInspector()

We need this for all OnInspectorGUI sub methods Public class CustomTransformComponent : Editor
