private void DrawChunkFormCreator()
    {
        var style = EditorStyles.largeLabel;

        style.fontStyle = FontStyle.Bold;
        EditorGUILayout.LabelField(new GUIContent("Terrain Form:"), style);

        EditorGUIExtensions.Space(2);

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Edit Chunks"))
        {
            if (EditorUtility.DisplayDialog("Start Editing Chunks", "This is going to open a new scene and close all currently open ones (saving them beforehand). Make sure there are no unwanted changes that would get saved in any open scene.", "Proceed"))
            {
                var sv = GetWindow <ChunkSceneView>(typeof(TerrainChunkWindow));

                sv.Initialize(this);

                sv.SetChunksToManage(chunksToManage);
                sv.Focus();
                sv.Show();

                //Docker.Dock(this, sv, Docker.DockPosition.Bottom);
            }
        }
        EditorGUILayout.EndHorizontal();
    }
Example #2
0
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     EditorGUI.BeginProperty(position, label, property);
     FillProps(property);
     EditorGUIExtensions.DrawPropertesWithLabelProperty(props, property, position);
     EditorGUI.EndProperty();
 }
Example #3
0
            private void DrawFollowToggles()
            {
                EditorGUI.BeginChangeCheck();

                string followPosDesc = KeybindingManager.instance.GetKeybindingDescription(FOLLOW_POSITION_KEYBINDING_ID);

                m_isFollowingPosition = EditorGUIExtensions.IconToggle(
                    EditorTextures.GetTexturePath(EditorTextures.GRID_TO_SELECTION_POSITION_UNLOCKED_ICON),
                    EditorTextures.GetTexturePath(EditorTextures.GRID_TO_SELECTION_POSITION_LOCKED_ICON),
                    m_isFollowingPosition,
                    "Stop grid from moving when the selected object is moved " + followPosDesc,
                    "Set grid to move when the selected object is moved " + followPosDesc);

                if (EditorGUI.EndChangeCheck() && m_isFollowingPosition)
                {
                    ResetFollowOffset();
                }

                string followRotDesc = KeybindingManager.instance.GetKeybindingDescription(FOLLOW_ROTATION_KEYBINDING_ID);

                m_isFollowingRotation = EditorGUIExtensions.IconToggle(
                    EditorTextures.GetTexturePath(EditorTextures.GRID_TO_SELECTION_ROTATION_UNLOCKED_ICON),
                    EditorTextures.GetTexturePath(EditorTextures.GRID_TO_SELECTION_ROTATION_LOCKED_ICON),
                    m_isFollowingRotation,
                    "Stop grid from rotating when the selected object is rotated " + followRotDesc,
                    "Set grid to rotate when the selected object is rotated " + followRotDesc);
            }
    private void DrawDensityFunctionChooser()
    {
        EditorGUILayout.LabelField(new GUIContent("Density Function Settings: "), EditorStyles.boldLabel);

        EditorGUIExtensions.Space(2);

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField(new GUIContent("Density Function Apply Mode: "));
        densityFuncApplyMode = (DensityFuncApplyMode)EditorGUILayout.EnumPopup(densityFuncApplyMode);
        EditorGUILayout.EndHorizontal();

        if (densityFuncApplyMode == DensityFuncApplyMode.OneForAll)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField($"Function: ");
            string buttonString = densityFunctionType != null?densityFunctionType.ToString() : "Chose";

            if (GUILayout.Button(buttonString, EditorStyles.popup))
            {
                Rect r = EditorGUILayout.GetControlRect();
                r.position = Event.current.mousePosition;
                DrawDensityFuncChooser(r);
            }
            EditorGUILayout.EndHorizontal();
        }

        if (GUILayout.Button("Create New Denisty Function"))
        {
            EditorWindow window = GetWindow <FunctionGraphEditor>(typeof(TerrainChunkWindow));
            window.Show();
        }
    }
Example #5
0
        public override void OnInspectorGUI()
        {
            #region Init
            blendee = (VertexBlendApplicator)target;
            #endregion

            #region Brush Settings
            GUILayout.Space(4);
            shouldDoBrush   = EditorGUILayout.ToggleLeft("Enable (Tab)", shouldDoBrush);
            displayVertices = EditorGUILayout.ToggleLeft("Display Vertices", displayVertices);
            maxRadius       = EditorGUILayout.FloatField("Radius", maxRadius);
            maxRadius       = Mathf.Abs(maxRadius);
            #endregion

            GUILayout.Space(8);

            doColorBrush = EditorGUILayout.ToggleLeft("Do Color", doColorBrush, (GUIStyle)"ShurikenModuleTitle");
            if (doColorBrush)
            {
                GUILayout.Space(4);
                paintColor = EditorGUILayout.ColorField("Color", paintColor);

                Rect colorShortcuts = EditorGUILayout.GetControlRect();
                Rect swatch         = colorShortcuts;
                swatch.x     += (colorShortcuts.width / 2);
                swatch.width  = 20;
                swatch.height = 20;

                for (int i = 0; i < colorSwatches.Length; i++)
                {
                    EditorGUI.DrawRect(swatch, Colors.BlackChocolate);
                    EditorGUI.DrawRect(swatch.WithPadding(4), colorSwatches[i]);
                    if (EditorGUIExtensions.RightClickOnRect(swatch))
                    {
                        paintColor = colorSwatches[i];
                        Repaint();
                    }

                    swatch.x = swatch.xMax + 2;
                }

                GUILayout.Space(8);
            }

            doHeightBrush = EditorGUILayout.ToggleLeft("Do Height", doHeightBrush, (GUIStyle)"ShurikenModuleTitle");
            if (doHeightBrush)
            {
                GUILayout.Space(4);
                texCoord3.z = EditorGUILayout.Slider("Height", texCoord3.z, -1, 1);
                GUILayout.Space(8);
            }

            doFalloffBrush = EditorGUILayout.ToggleLeft("Do Falloff", doFalloffBrush, (GUIStyle)"ShurikenModuleTitle");
            if (doFalloffBrush)
            {
                GUILayout.Space(4);
                texCoord3.w = EditorGUILayout.Slider("Falloff", texCoord3.w, 0.001f, 1);
                GUILayout.Space(8);
            }
        }
Example #6
0
            private void DrawGlobalOptions()
            {
                string visibilityDesc = KeybindingManager.instance.GetKeybindingDescription(VISIBILTY_TOGGLE_KEYBINDING_ID);

                m_isGridVisible = EditorGUIExtensions.IconToggle(EditorTextures.GetTexturePath(EditorTextures.HIDDEN_ICON), EditorTextures.GetTexturePath(EditorTextures.VISIBLE_ICON),
                                                                 m_isGridVisible, "Hide grid " + visibilityDesc, "Show grid " + visibilityDesc);

                string posSnapDesc = KeybindingManager.instance.GetKeybindingDescription(POSITION_ENABLED_KEYBINDING_ID);

                m_isPositionSnapEnabled = EditorGUIExtensions.IconToggle(EditorTextures.GetTexturePath(EditorTextures.POSITION_SNAP_DISABLED_ICON),
                                                                         EditorTextures.GetTexturePath(EditorTextures.POSITION_SNAP_ENABLED_ICON), m_isPositionSnapEnabled,
                                                                         "Disable position snapping " + posSnapDesc, "Enable position snapping " + posSnapDesc);

                string rotSnapDesc = KeybindingManager.instance.GetKeybindingDescription(ROTATION_ENABLED_KEYBINDING_ID);

                m_isRotationSnapEnabled = EditorGUIExtensions.IconToggle(EditorTextures.GetTexturePath(EditorTextures.ROTATION_SNAP_DISABLED_ICON),
                                                                         EditorTextures.GetTexturePath(EditorTextures.ROTATION_SNAP_ENABLED_ICON), m_isRotationSnapEnabled,
                                                                         "Disable rotation snapping " + rotSnapDesc, "Enable rotation snapping " + rotSnapDesc);

                EditorGUILayout.BeginVertical();
                {
                    EditorGUI.BeginDisabledGroup(!m_isRotationSnapEnabled);
                    {
                        EditorGUIExtensions.DrawIconPrefixedField(EditorTextures.GetTexturePath(EditorTextures.ROTATION_SNAP_ANGLE_ICON),
                                                                  "The angle in degrees used when rotation snapping is enabled",
                                                                  delegate
                        {
                            m_gridData.rotationSnapAngle = EditorGUILayout.FloatField(m_gridData.rotationSnapAngle,
                                                                                      GUILayout.MinWidth(MIN_FIELD_WIDTH));
                            m_gridData.rotationSnapAngle =
                                Mathf.Clamp(m_gridData.rotationSnapAngle, MIN_ROTATION_SNAP_ANGLE, MAX_ROTATION_SNAP_ANGLE);

                            // degree symbol
                            EditorGUILayout.LabelField(('\u00B0').ToString(), GUILayout.Width(UNIT_LABEL_WIDTH));
                        });
                    }
                    EditorGUI.EndDisabledGroup();

                    EditorGUI.BeginChangeCheck();
                    {
                        string tooltip = (m_gridData.edgeType == GridData.EdgeType.Infinite
                                                        ? "Display distance as number of grid cells"
                                                        : "Grid size (number of cells)");
                        EditorGUIExtensions.DrawIconPrefixedField(EditorTextures.GetTexturePath(EditorTextures.GRIDSIZE_ICON), tooltip,
                                                                  delegate
                        {
                            m_gridData.gridSize = EditorGUILayout.IntField(m_gridData.gridSize, GUILayout.MinWidth(MIN_FIELD_WIDTH));
                            m_gridData.gridSize = Mathf.Clamp(m_gridData.gridSize, MIN_GRID_SIZE, MAX_GRID_SIZE);
                            EditorGUILayout.LabelField("u", GUILayout.Width(UNIT_LABEL_WIDTH));
                        });
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        GridWindow.ResetSceneGrid();
                    }
                }
                EditorGUILayout.EndVertical();
            }
 public void General()
 {
     GUILayout.Space(4);
     EditorGUILayout.LabelField("General Settings", EditorStyles.boldLabel);
     accentColor           = EditorGUILayout.ColorField("Accent Color", accentColor);
     lightAccentColor      = EditorGUILayout.ColorField("Light Accent Color", lightAccentColor);
     shadedBackgroundColor = EditorGUILayout.ColorField("Background Color", shadedBackgroundColor);
     GUILayout.Label("Make Locked Unselectable");
     preventLockedFromSelection = EditorGUIExtensions.LayoutToggleSwitch(new string[] { "Enabled", "Disabled" }, preventLockedFromSelection, EditorStyles.miniButton);
 }
Example #8
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            FillProps(property);
            var h = EditorGUIExtensions.GetPropertesHeightWithLabelProperty(props, property);

            if (GetRectTransform(property) != null && property.isExpanded)
            {
                h += bh;
            }
            return(h);
        }
    private void DrawWithLayout()
    {
        Rect r = EditorGUILayout.BeginVertical();

        DrawGeneralInfoArea();
        EditorGUIExtensions.Space(5);
        DrawChunkFormCreator();
        EditorGUIExtensions.Space(5);
        DrawFooter();

        EditorGUILayout.BeginVertical();
    }
Example #10
0
        /// <summary>
        /// Renders the variable name for the element, which is
        /// a label that can be transformed into a text box for editing
        /// </summary>
        /// <param name="nameProperty">The property representing the variable name</param>
        /// <param name="index">The index of the item to render</param>
        /// <param name="isSelected">True if the item is currently selected, false if not</param>
        private void RenderVariableName(Rect rect, SerializedProperty nameProperty, int index, bool isSelected)
        {
            EditorGUI.BeginChangeCheck();

            string previousName      = nameProperty.stringValue;
            bool   previousExpansion = nameProperty.isExpanded;

            nameProperty.isExpanded = EditorGUIExtensions.EditableLabel(rect,
                                                                        nameProperty, nameProperty.isExpanded);

            if (EditorGUI.EndChangeCheck())
            {
                OnVariableNameChanged.SafeInvoke(this,
                                                 new ValueChangedEventArgs <string>(previousName, nameProperty.stringValue));
            }
        }
    private void DrawGeneralInfoArea()
    {
        var style = EditorStyles.largeLabel;

        style.fontStyle = FontStyle.Bold;
        EditorGUILayout.LabelField(new GUIContent("General Settings"), style);

        EditorGUIExtensions.Space(3);

        EditorGUILayout.BeginVertical();

        DrawChunkSettings();

        EditorGUIExtensions.Space(3);

        DrawDensityFunctionChooser();
        DrawChunks();
        EditorGUILayout.EndVertical();
    }
Example #12
0
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     FillProps(property);
     return(EditorGUIExtensions.GetPropertesHeightWithLabelProperty(props, property));
 }
Example #13
0
            public void DrawProperties()
            {
                if ((m_axis == Axis.X && !GridSettings.instance.showXAxisOptions) ||
                    (m_axis == Axis.Y && !GridSettings.instance.showYAxisOptions) ||
                    (m_axis == Axis.Z && !GridSettings.instance.showZAxisOptions))
                {
                    return;
                }

                AxisProperties axisProperties = m_gridData.GetAxisProperties(m_axis);

                EditorGUI.BeginChangeCheck();

                Color originalBGColor = GUI.backgroundColor;

                GUI.backgroundColor = GetAxisColor(m_axis);

                GUIStyle style = new GUIStyle(GUI.skin.box);

                style.normal.background = EditorTextures.GetByName(EditorTextures.BORDER_TEX_NAME);
                style.border            = new RectOffset(5, 5, 5, 5);

                if (GridSettings.instance.gridWindowLayout == LayoutDirection.Vertical)
                {
                    EditorGUILayout.BeginVertical(style);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal(style);
                }
                {
                    GUI.backgroundColor = originalBGColor;

                    m_isFoldoutOpen = EditorGUILayout.Foldout(m_isFoldoutOpen, m_axis + " Axis");

                    if (m_isFoldoutOpen)
                    {
                        // VISIBLE
                        axisProperties.isVisibleInEditor =
                            EditorGUIExtensions.IconToggle(EditorTextures.GetTexturePath(EditorTextures.HIDDEN_ICON),
                                                           EditorTextures.GetTexturePath(EditorTextures.VISIBLE_ICON),
                                                           axisProperties.isVisibleInEditor,
                                                           "Hide the " + m_axis + " grid plane",
                                                           "Show the " + m_axis + " grid plane");

                        // SNAP
                        axisProperties.isSnapEnabled =
                            EditorGUIExtensions.IconToggle(EditorTextures.GetTexturePath(EditorTextures.POSITION_SNAP_DISABLED_ICON),
                                                           EditorTextures.GetTexturePath(EditorTextures.POSITION_SNAP_ENABLED_ICON),
                                                           axisProperties.isSnapEnabled,
                                                           "Disable snapping along the " + m_axis + " axis",
                                                           "Enable snapping along the " + m_axis + " axis");

                        string unitAbbrev = UnitUtil.Abbreviation(GridSettings.instance.measurementUnit);

                        EditorGUILayout.BeginVertical();
                        {
                            // CELL SIZE
                            EditorGUIExtensions.DrawIconPrefixedField(EditorTextures.GetTexturePath(EditorTextures.CELL_SIZE_ICON),
                                                                      "Size of cells along the " + m_axis + " axis",
                                                                      delegate
                            {
                                axisProperties.cellSize = (float)EditorUnitUtil.DrawConvertedSizeField(axisProperties.cellSize,
                                                                                                       Unit.Meter, GridSettings.instance.measurementUnit, GridWindow.MIN_FIELD_WIDTH);
                                axisProperties.cellSize = Mathf.Max(axisProperties.cellSize, MIN_SIZE);

                                EditorGUILayout.LabelField(unitAbbrev, GUILayout.Width(GridWindow.UNIT_LABEL_WIDTH));
                            });

                            // GRID OFFSET
                            EditorGUIExtensions.DrawIconPrefixedField(EditorTextures.GetTexturePath(EditorTextures.GRID_OFFSET_ICON),
                                                                      "Offset of the entire grid along the " + m_axis + " axis",
                                                                      delegate
                            {
                                axisProperties.offset = (float)EditorUnitUtil.DrawConvertedSizeField(axisProperties.offset, Unit.Meter,
                                                                                                     GridSettings.instance.measurementUnit, GridWindow.MIN_FIELD_WIDTH);

                                EditorGUILayout.LabelField(unitAbbrev, GUILayout.Width(GridWindow.UNIT_LABEL_WIDTH));
                            });
                        }
                        EditorGUILayout.EndVertical();

                        // ROTATION
                        EditorGUIExtensions.DrawIconPrefixedField(EditorTextures.GetTexturePath(EditorTextures.ROTATION_SNAP_ANGLE_ICON),
                                                                  "Rotation of the grid around the " + m_axis + " axis",
                                                                  delegate
                        {
                            axisProperties.rotation = EditorGUILayout.FloatField(axisProperties.rotation,
                                                                                 GUILayout.MinWidth(GridWindow.MIN_FIELD_WIDTH));
                            axisProperties.rotation = Util.Wrap(axisProperties.rotation, MIN_AXIS_ROTATION, MAX_AXIS_ROTATION);

                            // degree symbol
                            EditorGUILayout.LabelField(('\u00B0').ToString(), GUILayout.Width(GridWindow.UNIT_LABEL_WIDTH));
                        });
                    }

                    GUI.backgroundColor = GetAxisColor(m_axis);
                }
                if (GridSettings.instance.gridWindowLayout == LayoutDirection.Vertical)
                {
                    EditorGUILayout.EndVertical();
                }
                else
                {
                    EditorGUILayout.EndHorizontal();
                }

                GUI.backgroundColor = originalBGColor;

                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(m_gridData);
                    SavePrefs();
                }
            }
Example #14
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();
        }
Example #15
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();
        }
Example #16
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();
        }
Example #17
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            FillProps(property);
            var h          = EditorGUIExtensions.DrawPropertesWithLabelProperty(props, property, position);
            var rectTransf = GetRectTransform(property);

            if (rectTransf != null && property.isExpanded)
            {
                var y  = position.y + h;
                var pw = position.width * 0.7f - 8f;
                var x  = position.x + position.width - pw - 4f;
                var bw = pw / 6f;

                var rect = rectTransf.rect;

                var anchorProp  = property.FindPropertyRelative("anchor");
                var offsetProp  = property.FindPropertyRelative("offset");
                var anchorPoint = new AnchorPoint()
                {
                    anchor = anchorProp.vector2Value, offset = offsetProp.vector2Value
                };

                //↑←→↓↔↕○□
                if (GUI.Button(new Rect(x, y, bw, bh), "←"))
                {
                    anchorPoint.SetAnchorWithSafePosition(new Vector2(0, anchorPoint.anchor.y), rect);
                }
                x += bw;

                if (GUI.Button(new Rect(x, y, bw, bh), "↑"))
                {
                    anchorPoint.SetAnchorWithSafePosition(new Vector2(anchorPoint.anchor.x, 1), rect);
                }
                x += bw;
                if (GUI.Button(new Rect(x, y, bw, bh), "↓"))
                {
                    anchorPoint.SetAnchorWithSafePosition(new Vector2(anchorPoint.anchor.x, 0), rect);
                }
                x += bw;
                if (GUI.Button(new Rect(x, y, bw, bh), "→"))
                {
                    anchorPoint.SetAnchorWithSafePosition(new Vector2(1, anchorPoint.anchor.y), rect);
                }
                x += bw + 3f;
                if (GUI.Button(new Rect(x, y, bw, bh), "↔"))
                {
                    var nax = (anchorPoint.CalcPos(rect) - rect.position).x / rect.width;
                    anchorPoint.anchor.x = nax;
                    anchorPoint.offset.x = 0;
                }
                x += bw;
                if (GUI.Button(new Rect(x, y, bw, bh), "↕"))
                {
                    var nay = (anchorPoint.CalcPos(rect) - rect.position).y / rect.height;
                    anchorPoint.anchor.y = nay;
                    anchorPoint.offset.y = 0;
                }

                anchorProp.vector2Value = anchorPoint.anchor;
                offsetProp.vector2Value = anchorPoint.offset;
            }

            EditorGUI.EndProperty();
        }