Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        private void DrawSettingsMenu(NavGridTool tool)
        {
            GUILayout.Label("Settings", EditorStyles.boldLabel);

            dNodeLimit(tool);
        }