public static void SetConstrainProportions(Transform[] transforms, bool enabled)
        {
            foreach (var t in transforms)
            {
                if (t == null)
                {
                    throw new ArgumentNullException("transform", "One or more transforms are null");
                }
            }

            ConstrainProportionsTransformScale.SetConstrainProportions(transforms, enabled);
        }
示例#2
0
        void Inspector3D()
        {
            EditorGUILayout.PropertyField(m_Position, s_Contents.positionContent);
            m_RotationGUI.RotationField();
            Transform t = target as Transform;

            if (t != null && m_ConstrainProportionsScale.Initialize(serializedObject.targetObjects) && m_ConstrainProportionsScaleProperty != null)
            {
                //AxisModified values [-1;2] : [none, x, y, z]
                int     axisModified = -1;
                var     mixedFields  = ConstrainProportionsTransformScale.GetMixedValueFields(m_Scale);
                Vector3 currentScale = m_ConstrainProportionsScale.DoGUI(EditorGUILayout.GetControlRect(true),
                                                                         s_Contents.scaleContent, m_Scale.vector3Value, serializedObject.targetObjects, ref axisModified, m_Scale, m_ConstrainProportionsScaleProperty);
                var mixedFieldsAfterGUI = ConstrainProportionsTransformScale.GetMixedValueFields(m_Scale);

                if (currentScale != m_Scale.vector3Value || mixedFields != mixedFieldsAfterGUI)
                {
                    if (serializedObject.targetObjectsCount > 1)
                    {
                        if (mixedFields != mixedFieldsAfterGUI)
                        {
                            axisModified = -1;
                            for (int i = 0; i < 3; i++)
                            {
                                if (ConstrainProportionsTransformScale.IsBit(mixedFields, i) && !ConstrainProportionsTransformScale.IsBit(mixedFieldsAfterGUI, i))
                                {
                                    axisModified = i;
                                    break;
                                }
                            }
                        }

                        if (axisModified != -1)
                        {
                            m_IsScaleDirty = ConstrainProportionsTransformScale.HandleMultiSelectionScaleChanges(
                                m_Scale.vector3Value,
                                currentScale, m_ConstrainProportionsScale.constrainProportionsScale,
                                serializedObject.targetObjects, ref axisModified);
                        }
                    }

                    if (currentScale != m_Scale.vector3Value)
                    {
                        m_Scale.vector3Value = currentScale;
                    }
                }
            }
            else
            {
                EditorGUILayout.PropertyField(m_Scale, s_Contents.scaleContent);
            }
        }
示例#3
0
        public void OnEnable()
        {
            m_Position = serializedObject.FindProperty("m_LocalPosition");
            m_Scale    = serializedObject.FindProperty("m_LocalScale");
            m_ConstrainProportionsScaleProperty = serializedObject.FindProperty("m_ConstrainProportionsScale");

            if (m_RotationGUI == null)
            {
                m_RotationGUI = new TransformRotationGUI();
            }
            m_RotationGUI.OnEnable(serializedObject.FindProperty("m_LocalRotation"), EditorGUIUtility.TrTextContent("Rotation", "The local rotation of this GameObject relative to the parent."));
            m_ConstrainProportionsScale = new ConstrainProportionsTransformScale(m_Scale.vector3Value);
        }
        static void SetupAction(SerializedProperty property, GenericMenu menu, Event evt,
                                Action <SerializedProperty> copyFunc,
                                Func <SerializedProperty, bool> canPasteFunc,
                                Action <SerializedProperty> pasteFunc)
        {
            var canCopy  = !property.hasMultipleDifferentValues;
            var canPaste = GUI.enabled && canPasteFunc(property);

            if (menu != null)
            {
                AddSeparator(menu);

                var copyContent = overrideCopyContent ?? kCopyContent;
                if (canCopy)
                {
                    menu.AddItem(copyContent, false, o => copyFunc((SerializedProperty)o), property);
                }
                else
                {
                    menu.AddDisabledItem(copyContent);
                }

                var pasteContent = overridePasteContent ?? kPasteContent;
                if (canPaste)
                {
                    menu.AddItem(pasteContent, false,
                                 delegate(object o)
                    {
                        var prop = (SerializedProperty)o;
                        pasteFunc(prop);
                        prop.serializedObject.ApplyModifiedProperties();
                        // Constrain proportions scale widget might need extra recalculation, notify if a paste
                        ConstrainProportionsTransformScale.NotifyPropertyPasted(prop.propertyPath);
                    }, property);
                }
                else
                {
                    menu.AddDisabledItem(pasteContent);
                }
            }

            if (evt != null)
            {
                if (canCopy && evt.commandName == EventCommandNames.Copy)
                {
                    if (evt.type == EventType.ValidateCommand)
                    {
                        evt.Use();
                    }
                    if (evt.type == EventType.ExecuteCommand)
                    {
                        copyFunc(property);
                        evt.Use();
                    }
                }
                if (canPaste && evt.commandName == EventCommandNames.Paste)
                {
                    if (evt.type == EventType.ValidateCommand)
                    {
                        evt.Use();
                    }
                    if (evt.type == EventType.ExecuteCommand)
                    {
                        pasteFunc(property);
                        property.serializedObject.ApplyModifiedProperties();
                        evt.Use();
                    }
                }
            }
        }