Exemple #1
0
            private void DrawGridField()
            {
                EditorGUI.BeginChangeCheck();
                m_gridData = EditorGUILayout.ObjectField(m_gridData, typeof(GridData), false) as GridData;

                GUIContent addNewGridDataGUIContent = new GUIContent(EditorTextures.GetByName(EditorTextures.ADD_NEW_ICON),
                                                                     "Create new GridData with default settings");

                if (GUILayout.Button(addNewGridDataGUIContent, GUILayout.Height(BUTTON_HEIGHT)))
                {
                    m_gridData             = CreateNewGridData("New GridData");
                    Selection.activeObject = m_gridData;
                }

                GUIContent duplicateGridDataGUIContent = new GUIContent(EditorTextures.GetByName(EditorTextures.DUPLICATE_ICON),
                                                                        "Duplicate the currently selected GridData");

                if (GUILayout.Button(duplicateGridDataGUIContent, GUILayout.Height(BUTTON_HEIGHT)))
                {
                    string path     = AssetDatabase.GetAssetPath(m_gridData);
                    string copyPath = AssetDatabase.GenerateUniqueAssetPath(path.Replace(".asset", string.Empty) + " Copy.asset");
                    AssetDatabase.CopyAsset(path, copyPath);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    m_gridData             = AssetDatabase.LoadAssetAtPath(copyPath, typeof(GridData)) as GridData;
                    Selection.activeObject = m_gridData;
                }

                if (EditorGUI.EndChangeCheck())
                {
                    SelectGridData(m_gridData);
                }
            }
Exemple #2
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);
            }
Exemple #3
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 static void DrawIconPrefixedField(string iconPath, string tooltip, IconPrefixedFieldCallback callback)
 {
     EditorGUILayout.BeginHorizontal();
     {
         GUIContent guiContent = new GUIContent(EditorTextures.GetByPath(iconPath), tooltip);
         EditorGUILayout.LabelField(guiContent, GUILayout.Width(20f));
         callback();
     }
     EditorGUILayout.EndHorizontal();
 }
Exemple #5
0
            private void DrawHorizontalLayout()
            {
                EditorGUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button(new GUIContent(EditorTextures.GetByName(EditorTextures.SETTINGS_ICON)), GUILayout.Width(UNIT_LABEL_WIDTH)))
                    {
                        Selection.activeObject = GridSettings.instance;
                    }

                    DrawBarItems();
                }
                EditorGUILayout.EndHorizontal();
            }
            public static bool IconToggle(string disabledIconPath, string enabledIconPath, bool value,
                                          string tooltipWhenEnabled, string tooltipWhenDisabled)
            {
                string    texturePath = (value ? enabledIconPath : disabledIconPath);
                Texture2D texture     = EditorTextures.GetByPath(texturePath);

                string tooltip = (value ? tooltipWhenEnabled : tooltipWhenDisabled);

                if (GUILayout.Button(new GUIContent(texture, tooltip), GUILayout.Height(GridWindow.BUTTON_HEIGHT)))
                {
                    return(!value);
                }

                return(value);
            }
Exemple #7
0
 private void DrawGridMoveButtons()
 {
     EditorGUI.BeginDisabledGroup(Selection.activeTransform == null);
     {
         if (GUILayout.Button(new GUIContent(EditorTextures.GetByName(EditorTextures.GRID_TO_SELECTION_POSITION_ICON),
                                             "Moves the entire grid to match the position of the active selected object "
                                             + KeybindingManager.instance.GetKeybindingDescription(MOVE_TO_SELECTED_KEYBINDING_ID)),
                              GUILayout.Height(BUTTON_HEIGHT)))
         {
             MoveGridToSelected();
         }
         if (GUILayout.Button(new GUIContent(EditorTextures.GetByName(EditorTextures.GRID_TO_SELECTION_ROTATION_ICON),
                                             "Rotates the entire grid to match the rotation of the active selected object "
                                             + KeybindingManager.instance.GetKeybindingDescription(ROTATE_TO_SELECTED_KEYBINDING_ID)),
                              GUILayout.Height(BUTTON_HEIGHT)))
         {
             RotateGridToSelected();
         }
     }
     EditorGUI.EndDisabledGroup();
 }
Exemple #8
0
            public static Texture2D GetByPath(string path)
            {
                if (s_loadedTextures == null)
                {
                    s_loadedTextures = new Dictionary <string, Texture2D>();
                }

                Texture2D tex2D;

                if (s_loadedTextures.TryGetValue(path, out tex2D))
                {
                    return(tex2D);
                }

                tex2D = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
                if (tex2D == null)
                {
                    tex2D = AssetDatabase.LoadAssetAtPath(EditorTextures.GetTexturePath(EditorTextures.MISSING_TEX_NAME),
                                                          typeof(Texture2D)) as Texture2D;
                }

                return(tex2D);
            }
Exemple #9
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();
                }
            }