Ejemplo n.º 1
0
        void DrawLocalRotationGUI()
        {
            // Setup.
            GUILayout.Space(2);
            EditorGUI.BeginProperty(GUILayoutUtility.GetLastRect(), new GUIContent(string.Empty), localRotation);
            EditorGUILayout.BeginHorizontal();

            // If Rotation has been modified outside, the euler hint will not be modified and the value displayed in the inspector will be wrong.
            // If in animation mode, this creates keys every time we move the playhead since the values are changed by the animation manager.

            if (!serializedObject.isEditingMultipleObjects && !AnimationMode.InAnimationMode())
            {
                if (Quaternion.Angle(Quaternion.Euler(targetTransform.localEulerAngles), Quaternion.Euler(localEulerHint.vector3Value)) > 0.06f)
                {
                    localEulerHint.vector3Value = localRotation.quaternionValue.eulerAngles;
                    GUI.changed = true;
                }
            }

            Vector3 eulerHintCache = localEulerHint.vector3Value;

            // Label.
            EditorGUILayout.LabelField("Rotation", GUILayout.Width(59));

            #region Label Shortcuts
            EditorGUI.BeginChangeCheck();
            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                GUIUtility.keyboardControl = 0;
                eulerHintCache             = Vector3.zero;
                GUI.changed = true;
            }
            if (EditorGUIExtensions.CtrlShiftRightClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                ClipboardData.clipboardRotation = eulerHintCache;
            }
            if (EditorGUIExtensions.CtrlRightClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                eulerHintCache = ClipboardData.clipboardRotation;
                GUI.changed    = true;
            }

            if (EditorGUI.EndChangeCheck())
            {
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    SerializedProperty hintProp = serial.FindProperty("m_LocalEulerAnglesHint");
                    hintProp.vector3Value = eulerHintCache;
                    serial.FindProperty("m_LocalRotation").quaternionValue = Quaternion.Euler(hintProp.vector3Value);
                    serial.ApplyModifiedProperties();
                }
            }
            #endregion

            #region X Value
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = IsEntireSelectionEqualInXRot() ? false : true;
            eulerHintCache.x         = EditorGUILayout.FloatField("X", eulerHintCache.x, GUILayout.MinWidth(12));

            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                GUIUtility.keyboardControl = 0;
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    SerializedProperty hintProp = serial.FindProperty("m_LocalEulerAnglesHint");
                    hintProp.vector3Value = hintProp.vector3Value.WithX(0);
                    serial.FindProperty("m_LocalRotation").quaternionValue = Quaternion.Euler(hintProp.vector3Value);
                    serial.ApplyModifiedProperties();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    SerializedProperty hintProp = serial.FindProperty("m_LocalEulerAnglesHint");
                    hintProp.vector3Value = hintProp.vector3Value.WithX(eulerHintCache.x);
                    serial.FindProperty("m_LocalRotation").quaternionValue = Quaternion.Euler(hintProp.vector3Value);
                    serial.ApplyModifiedProperties();
                }
            }
            #endregion

            #region Y Value
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = IsEntireSelectionEqualInYRot() ? false : true;
            eulerHintCache.y         = EditorGUILayout.FloatField("Y", eulerHintCache.y, GUILayout.MinWidth(12));

            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                GUIUtility.keyboardControl = 0;
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    SerializedProperty prop = serial.FindProperty("m_LocalEulerAnglesHint");
                    prop.vector3Value = prop.vector3Value.WithY(0);
                    serial.FindProperty("m_LocalRotation").quaternionValue = Quaternion.Euler(prop.vector3Value);
                    serial.ApplyModifiedProperties();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    SerializedProperty hintProp = serial.FindProperty("m_LocalEulerAnglesHint");
                    hintProp.vector3Value = hintProp.vector3Value.WithY(eulerHintCache.y);
                    serial.FindProperty("m_LocalRotation").quaternionValue = Quaternion.Euler(hintProp.vector3Value);
                    serial.ApplyModifiedProperties();
                }
            }

            #endregion

            #region Z Value
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = IsEntireSelectionEqualInZRot() ? false : true;
            eulerHintCache.z         = EditorGUILayout.FloatField("Z", eulerHintCache.z, GUILayout.MinWidth(12));

            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                GUIUtility.keyboardControl = 0;
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    SerializedProperty prop = serial.FindProperty("m_LocalEulerAnglesHint");
                    prop.vector3Value = prop.vector3Value.WithZ(0);
                    serial.FindProperty("m_LocalRotation").quaternionValue = Quaternion.Euler(prop.vector3Value);
                    serial.ApplyModifiedProperties();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    SerializedProperty hintProp = serial.FindProperty("m_LocalEulerAnglesHint");
                    hintProp.vector3Value = hintProp.vector3Value.WithZ(eulerHintCache.z);
                    serial.FindProperty("m_LocalRotation").quaternionValue = Quaternion.Euler(hintProp.vector3Value);
                    serial.ApplyModifiedProperties();
                }
            }
            #endregion

            // End Block.
            EditorGUI.showMixedValue = false;
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndProperty();
        }
Ejemplo n.º 2
0
        void DrawLocalScaleGUI()
        {
            // Setup.
            GUILayout.Space(2);
            EditorGUI.BeginProperty(GUILayoutUtility.GetLastRect(), new GUIContent(string.Empty), localScale);
            EditorGUILayout.BeginHorizontal();

            Vector3 sclCache = localScale.vector3Value;

            // Label.
            EditorGUILayout.LabelField("Scale", GUILayout.Width(55 - 16));

            #region Label Shortcuts
            EditorGUI.BeginChangeCheck();
            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                sclCache    = Vector3.one;
                GUI.changed = true;
            }
            if (EditorGUIExtensions.CtrlShiftRightClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                ClipboardData.clipboardRotation = targetTransform.localScale;
            }
            if (EditorGUIExtensions.CtrlRightClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                sclCache    = ClipboardData.clipboardRotation;
                GUI.changed = true;
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    serial.FindProperty("m_LocalScale").vector3Value = sclCache;
                    serial.ApplyModifiedProperties();
                }
            }
            #endregion

            EditorGUI.showMixedValue = false;
            combinedScale            = EditorGUILayout.Toggle(combinedScale, Ressources.bToolsSkin.customStyles[1], GUILayout.Width(16), GUILayout.Height(16));
            EditorPrefs.SetBool("bToolsCombinedScale", combinedScale);

            if (!combinedScale)
            {             //Draw single fields
                #region X Value
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = IsEntireSelectionEqualInXScl() ? false : true;
                sclCache.x = EditorGUILayout.FloatField("X", sclCache.x, GUILayout.MinWidth(12));

                if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
                {
                    foreach (var obj in targets)
                    {
                        SerializedObject serial = new SerializedObject(obj);
                        serial.Update();
                        serial.FindProperty("m_LocalScale").vector3Value = serial.FindProperty("m_LocalScale").vector3Value.WithX(1);
                        serial.ApplyModifiedProperties();
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (var obj in targets)
                    {
                        SerializedObject serial = new SerializedObject(obj);
                        serial.Update();
                        serial.FindProperty("m_LocalScale").vector3Value = serial.FindProperty("m_LocalScale").vector3Value.WithX(sclCache.x);
                        serial.ApplyModifiedProperties();
                    }
                }
                #endregion

                #region Y Value
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = IsEntireSelectionEqualInYScl() ? false : true;
                sclCache.y = EditorGUILayout.FloatField("Y", sclCache.y, GUILayout.MinWidth(12));
                if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
                {
                    foreach (var obj in targets)
                    {
                        SerializedObject serial = new SerializedObject(obj);
                        serial.Update();
                        serial.FindProperty("m_LocalScale").vector3Value = serial.FindProperty("m_LocalScale").vector3Value.WithY(1);
                        serial.ApplyModifiedProperties();
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (var obj in targets)
                    {
                        SerializedObject serial = new SerializedObject(obj);
                        serial.Update();
                        serial.FindProperty("m_LocalScale").vector3Value = serial.FindProperty("m_LocalScale").vector3Value.WithY(sclCache.y);
                        serial.ApplyModifiedProperties();
                    }
                }
                #endregion

                #region Z Value
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = IsEntireSelectionEqualInZScl() ? false : true;
                sclCache.z = EditorGUILayout.FloatField("Z", sclCache.z, GUILayout.MinWidth(12));

                if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
                {
                    foreach (var obj in targets)
                    {
                        SerializedObject serial = new SerializedObject(obj);
                        serial.Update();
                        serial.FindProperty("m_LocalScale").vector3Value = serial.FindProperty("m_LocalScale").vector3Value.WithZ(1);
                        serial.ApplyModifiedProperties();
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (var obj in targets)
                    {
                        SerializedObject serial = new SerializedObject(obj);
                        serial.Update();
                        serial.FindProperty("m_LocalScale").vector3Value = serial.FindProperty("m_LocalScale").vector3Value.WithZ(sclCache.z);
                        serial.ApplyModifiedProperties();
                    }
                }
                #endregion
            }
            else
            {             // Else, draw combined scale.
                if (localScale.vector3Value.x != localScale.vector3Value.y || localScale.vector3Value.y != localScale.vector3Value.z || !IsEntireSelectionEqualInScale())
                {
                    EditorGUI.showMixedValue = true;
                }
                else
                {
                    EditorGUI.showMixedValue = false;
                }

                float monoScale;
                monoScale = localScale.vector3Value.x;

                EditorGUI.BeginChangeCheck();
                monoScale = EditorGUILayout.FloatField("S", monoScale);

                // SAVE
                if (EditorGUI.EndChangeCheck())
                {
                    Vector3 newMonoScale = new Vector3(monoScale, monoScale, monoScale);
                    localScale.vector3Value = newMonoScale;
                }
            }

            // End block.
            EditorGUI.showMixedValue = false;
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndProperty();
        }
Ejemplo n.º 3
0
        void DrawLocalPositionGUI()
        {
            // Setup.
            GUILayout.Space(6);
            EditorGUI.BeginChangeCheck();
            EditorGUI.BeginProperty(GUILayoutUtility.GetLastRect(), new GUIContent(string.Empty), localPosition);
            EditorGUILayout.BeginHorizontal();
            Vector3 positionCache = localPosition.vector3Value;

            // Label.
            EditorGUILayout.LabelField("Position", GUILayout.Width(59));

            #region Label Shortcuts
            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                GUIUtility.keyboardControl = 0;
                positionCache = Vector3.zero;
                GUI.changed   = true;
            }
            if (EditorGUIExtensions.CtrlShiftRightClickOnRect(GUILayoutUtility.GetLastRect()))
            {             // Save position into clipboard
                ClipboardData.clipboardPosition = targetTransform.localPosition;
            }
            if (EditorGUIExtensions.CtrlRightClickOnRect(GUILayoutUtility.GetLastRect()))
            {             // Load position into clipboard
                positionCache = ClipboardData.clipboardPosition;
                GUI.changed   = true;
            }

            if (EditorGUI.EndChangeCheck())
            {
                GUIUtility.keyboardControl = 0;
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    serial.FindProperty("m_LocalPosition").vector3Value = positionCache;
                    serial.ApplyModifiedProperties();
                }
            }
            #endregion

            #region X Value
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = IsEntireSelectionEqualInXPos() ? false : true;
            positionCache.x          = EditorGUILayout.FloatField("X", positionCache.x, GUILayout.MinWidth(12));

            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                GUIUtility.keyboardControl = 0;
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    serial.FindProperty("m_LocalPosition").vector3Value = serial.FindProperty("m_LocalPosition").vector3Value.WithX(0);
                    serial.ApplyModifiedProperties();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    serial.FindProperty("m_LocalPosition").vector3Value = serial.FindProperty("m_LocalPosition").vector3Value.WithX(positionCache.x);
                    serial.ApplyModifiedProperties();
                }
            }
            #endregion

            #region Y Value
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = IsEntireSelectionEqualInYPos() ? false : true;
            positionCache.y          = EditorGUILayout.FloatField("Y", positionCache.y, GUILayout.MinWidth(12));

            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                GUIUtility.keyboardControl = 0;
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    serial.FindProperty("m_LocalPosition").vector3Value = serial.FindProperty("m_LocalPosition").vector3Value.WithY(0);
                    serial.ApplyModifiedProperties();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    serial.FindProperty("m_LocalPosition").vector3Value = serial.FindProperty("m_LocalPosition").vector3Value.WithY(positionCache.y);
                    serial.ApplyModifiedProperties();
                }
            }
            #endregion

            #region Z Value
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = IsEntireSelectionEqualInZPos() ? false : true;
            positionCache.z          = EditorGUILayout.FloatField("Z", positionCache.z, GUILayout.MinWidth(12));
            if (EditorGUIExtensions.ScrollWheelClickOnRect(GUILayoutUtility.GetLastRect()))
            {
                GUIUtility.keyboardControl = 0;
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    serial.FindProperty("m_LocalPosition").vector3Value = serial.FindProperty("m_LocalPosition").vector3Value.WithZ(0);
                    serial.ApplyModifiedProperties();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (var obj in targets)
                {
                    SerializedObject serial = new SerializedObject(obj);
                    serial.Update();
                    serial.FindProperty("m_LocalPosition").vector3Value = serial.FindProperty("m_LocalPosition").vector3Value.WithZ(positionCache.z);
                    serial.ApplyModifiedProperties();
                }
            }

            #endregion

            // End block.
            EditorGUI.showMixedValue = false;
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndProperty();
        }