Exemplo n.º 1
0
        private static bool DrawSubGridHandle(SubGrid subGrid, SubGrid activeSubGrid, Color subGridColor)
        {
            Vector2Int subGridOriginPosition = subGrid.GetOriginCoordinate();
            Vector3    subGridWorldPosition  = subGrid.GetNavGrid().GetOriginWorldPosition() + new Vector3(subGridOriginPosition.x, 0, subGridOriginPosition.y);

            Vector3[] vertexs =
            {
                subGridWorldPosition,                                                 //Bottom-Left
                subGridWorldPosition + new Vector3(subGrid.Width, 0, 0),              //Bottom-Right

                subGridWorldPosition + new Vector3(subGrid.Width, 0, subGrid.Height), //Top-Right
                subGridWorldPosition + new Vector3(0,             0, subGrid.Height)  //Top-Left
            };

            Handles.DrawSolidRectangleWithOutline(vertexs, subGridColor, Color.black);

            if (subGrid.Equals(activeSubGrid))
            {
                return(false);
            }

            float centerX = vertexs[0].x + ((vertexs[1].x - vertexs[0].x) / 2f);
            float centerZ = vertexs[0].z + ((vertexs[3].z - vertexs[0].z) / 2f);

            Vector3 centerPosition = new Vector3(centerX, vertexs[0].y, centerZ);

            float buttonSize = 6f;

            if (Handles.Button(centerPosition, Quaternion.LookRotation(Vector3.up), buttonSize, buttonSize, Handles.RectangleHandleCap))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        //Divides the provided subgrid using the provided devisions
        private static List <SubGrid> DivideSubGrid(SubGrid currentSubGrid, NavGrid navGrid, Vector2 divisions)
        {
            int width  = currentSubGrid.Width;
            int height = currentSubGrid.Height;

            List <SubGrid> newSubGrids = new List <SubGrid>();

            float widthDivisions  = divisions.x;
            float heightDivisions = divisions.y;

            Vector2Int originCoordinate  = currentSubGrid.GetOriginCoordinate();
            Vector2Int currentCoordinate = originCoordinate;

            int xSize = Mathf.CeilToInt(width / widthDivisions);
            int ySize = Mathf.CeilToInt(height / heightDivisions);

            for (int y = 0; y < heightDivisions; y++)
            {
                //Correct ySize on the final row
                if (y == heightDivisions - 1)
                {
                    ySize = height - Mathf.RoundToInt(currentCoordinate.y - originCoordinate.y);
                }

                currentCoordinate.x = originCoordinate.x;
                for (int x = 0; x < widthDivisions; x++)
                {
                    SubGrid newSubGrid;

                    //Correct xSize on the final column
                    if (x == widthDivisions - 1)
                    {
                        newSubGrid = new SubGrid(navGrid, currentSubGrid, currentCoordinate, width - Mathf.RoundToInt(currentCoordinate.x - originCoordinate.x), ySize);
                    }
                    else
                    {
                        newSubGrid = new SubGrid(navGrid, currentSubGrid, currentCoordinate, xSize, ySize);
                    }

                    currentSubGrid.AddChildSubGrid(newSubGrid);
                    newSubGrids.Add(newSubGrid);

                    currentCoordinate.x += xSize;
                }

                currentCoordinate.y += ySize;
            }

            return(newSubGrids);
        }
Exemplo n.º 3
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);
                        }
                    }
                }
            }
        }