Example #1
0
        private void dNodeControls(NavGridTool tool)
        {
            Vector2Int selectedNode = tool.SelectedNode;

            GUILayout.BeginVertical("box");
            {
                GUILayout.Label("Selected Node", EditorStyles.boldLabel);

                if (selectedNode.Equals(NavGrid.NO_NODE))
                {
                    GUILayout.Label("No Node Selected");
                }
                else
                {
                    GUILayout.Label("Node: (" + selectedNode.x + ", " + selectedNode.y + ")");

                    if (GUILayout.Button("Parent SubGrid"))
                    {
                        tool.SelectParentSubGrid();
                    }

                    if (GUILayout.Button("Open Grid Here"))
                    {
                        tool.CreateSubGridAtSelection();
                    }
                }
            }
            GUILayout.EndVertical();
        }
Example #2
0
        public void Render2DGUI(NavGridTool tool)
        {
            //Title and Tabs
            GUILayout.BeginVertical("box");
            {
                DrawTitle();
                DrawTabSelection();
            }
            GUILayout.EndVertical();
            GUILayout.Space(20);

            //Render Selected Tab
            GUILayout.BeginVertical("box");
            {
                switch (selectedTab)
                {
                //Tools
                case 0:
                    DrawToolsMenu(tool);
                    GUILayout.Space(15);
                    dNodeControls(tool);
                    DrawModeControls(tool);
                    break;

                //Settings
                case 1:
                    DrawSettingsMenu(tool);
                    DrawModeControls(tool);
                    break;
                }
            }
            GUILayout.EndVertical();
        }
Example #3
0
        private void DrawToolsMenu(NavGridTool tool)
        {
            int selectedTool = tool.SelectedTool;

            GUILayout.Label("Tools", EditorStyles.boldLabel);
            GUILayout.BeginHorizontal("box");
            {
                GUILayout.FlexibleSpace();

                string[] toolLabels = new string[] { "Select", "Single", "Square", "Wall Mode" };

                int newTool = GUILayout.SelectionGrid(
                    selectedTool,
                    toolLabels,
                    4,
                    EditorStyles.toolbarButton,
                    GUILayout.Width(300));

                if (newTool != selectedTool)
                {
                    tool.SelectedTool = newTool;
                    tool.UnselectNode();
                }

                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();
        }
Example #4
0
        public void DrawSubGrid(NavGridTool tool)
        {
            if (currentMode != Mode.EDIT)
            {
                return;
            }



            SubGrid selectedSubGrid = tool.SelectedSubGrid;

            List <SubGrid> subGrids = selectedSubGrid.GetChildSubGrids();

            //If the current SubGrid has child SubGrids
            if (subGrids.Count > 0)
            {
                DrawSubGridHandle(selectedSubGrid, selectedSubGrid, SUBGRID_COLOR);

                for (int i = 0; i < subGrids.Count; i++)
                {
                    if (DrawSubGridHandle(subGrids[i], selectedSubGrid, SUBGRID_COLOR))
                    {
                        tool.SelectChildSubGrid(i);
                        return;
                    }
                }
            }
            else
            {
                DrawNodeHandles(tool, selectedSubGrid);
            }
        }
Example #5
0
        private static void HandleNodeClick(SubGrid subGrid, Vector2Int nodeCoordinates)
        {
            //Get the active instance of NavGridTool and send it the NodeClick
            NavGridTool navGridTool = (EditorWindow.GetWindow(typeof(NavGridTool)) as NavGridTool);

            navGridTool.HandleNodeClick(nodeCoordinates);
        }
Example #6
0
        private void dNodeLimit(NavGridTool tool)
        {
            tool.NODE_RENDER_LIMIT = Mathf.Clamp(EditorGUILayout.IntField("Node Render Limit", tool.NODE_RENDER_LIMIT), 25, 10000);

            if (GUILayout.Button("Apply Now"))
            {
                tool.RegenerateSubGrids();
            }
        }
Example #7
0
        private void DrawModeControls(NavGridTool tool)
        {
            GUILayout.BeginHorizontal("box");
            {
                // Render Toggle
                if (NavGridTool3DGUI.currentMode == NavGridTool3DGUI.Mode.RENDER || NavGridTool3DGUI.currentMode == NavGridTool3DGUI.Mode.EDIT)
                {
                    if (GUILayout.Button("Disable Render"))
                    {
                        tool.GUI3D.SetMode(NavGridTool3DGUI.Mode.DISABLED);
                        tool.UnselectNode();
                    }
                }
                else
                {
                    if (GUILayout.Button("Enable Render"))
                    {
                        tool.GUI3D.SetMode(NavGridTool3DGUI.Mode.RENDER);
                    }
                }

                // View | Edit Mode
                if (NavGridTool3DGUI.currentMode == NavGridTool3DGUI.Mode.DISABLED)
                {
                    GUILayout.Button("...");
                }
                else
                {
                    if (NavGridTool3DGUI.currentMode == NavGridTool3DGUI.Mode.RENDER)
                    {
                        if (GUILayout.Button("Edit Mode ->"))
                        {
                            tool.GUI3D.SetMode(NavGridTool3DGUI.Mode.EDIT);
                            tool.RegenerateSubGrids();
                        }
                    }
                    else if (NavGridTool3DGUI.currentMode == NavGridTool3DGUI.Mode.EDIT)
                    {
                        if (GUILayout.Button("Render Mode ->"))
                        {
                            tool.GUI3D.SetMode(NavGridTool3DGUI.Mode.RENDER);
                            tool.UnselectNode();
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
Example #8
0
        static void OnDrawGizmosSelected(NavGrid grid, GizmoType type)
        {
            if (currentMode != NavGridTool3DGUI.Mode.RENDER)
            {
                return;
            }

            NavGridTool tool = EditorWindow.GetWindow(typeof(NavGridTool), false, "", false) as NavGridTool;

            //Draw each node
            for (int y = 0; y < grid.Height; y++)
            {
                for (int x = 0; x < grid.Width; x++)
                {
                    Gizmos.color = tool.ChooseNodeColor(new Vector2Int(x, y));
                    Gizmos.DrawCube(grid.GetOriginWorldPosition() + new Vector3(x, 0, y), Vector3.one * 0.45f);
                }
            }
        }
Example #9
0
        private void DrawNodeHandles(NavGridTool tool, SubGrid subGrid)
        {
            float NODE_SIZE = 0.45f;

            NavGrid navGrid = subGrid.GetNavGrid();

            Vector2Int subGridOriginPosition = subGrid.GetOriginCoordinate();
            Vector3    subGridWorldPosition  = navGrid.GetOriginWorldPosition() + new Vector3(subGridOriginPosition.x, 0, subGridOriginPosition.y);

            int width  = subGrid.Width;
            int height = subGrid.Height;

            //Draw each node
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Vector2Int nodeCoordinates =
                        new Vector2Int(
                            subGridOriginPosition.x + x,
                            subGridOriginPosition.y + y
                            );

                    Handles.color = tool.ChooseNodeColor(nodeCoordinates);

                    if (currentMode == Mode.EDIT)
                    {
                        //Draw nodes as buttons and watch for input
                        if (Handles.Button(subGridWorldPosition + new Vector3(x, 0, y), Quaternion.LookRotation(Vector3.up), NODE_SIZE, NODE_SIZE, Handles.CubeHandleCap))
                        {
                            HandleNodeClick(subGrid, nodeCoordinates);
                        }
                    }
                }
            }
        }
Example #10
0
        private void DrawSettingsMenu(NavGridTool tool)
        {
            GUILayout.Label("Settings", EditorStyles.boldLabel);

            dNodeLimit(tool);
        }