Example #1
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();
                }
            }