コード例 #1
0
        /// <summary>
        /// Mainline method: Creates a hexagon grid.
        /// </summary>
        /// <param name="blueprint">The size as well as the type of elements included in the grid.</param>
        /// <param name="prefab">A prefab reference to create said grid.</param>
        /// <returns>A 2D array of the hexagon grid.</returns>
        public static TestBoardModel.Board CreateHexagonGrid(int[,] blueprint, NodeObject prefab)
        {
            Transform parent   = CreateCanvas($"{prefab.name}'s list.");
            Board     newBoard = new TestBoardModel.Board(blueprint.GetLength(0), blueprint.GetLength(1));

            globalNodeViewList = new List <NodeObject>();
            int xPos;

            for (int x = 0; x < blueprint.GetLength(0); x++)
            {
                for (int y = 0; y < blueprint.GetLength(1); y++)
                {
                    xPos = y - x / 2;
                    Team currentTeam =
                        (blueprint[x, y] > 8 && blueprint[x, y] != 11) ?
                        (blueprint[x, y] == 14 || blueprint[x, y] == 19) ?
                        Team.BigRed : (blueprint[x, y] == 16 || blueprint[x, y] == 17) ?
                        Team.BigGreen : Team.Unoccupied :
                        (Team)blueprint[x, y]; //O: Massive condition to limit only the bigRed and bigGreen to be used when nessesary.
                    Vector2Int boardPos  = new Vector2Int(x, y);
                    Vector2    objectPos = SetPosition(new Vector2Int(x, xPos) - new Vector2(newBoard.GetLength(0) / centerPointX, newBoard.GetLength(1) / centerPointY));
                    //Like here (O)
                    newBoard[x, y] = new BoardNode(boardPos, objectPos, currentTeam);

                    //The NodeObject uses the raw information to set its proper color on the node.
                    globalNodeViewList.Add(NodeObject.CreateNodeObject(prefab, objectPos, (NodeColor)blueprint[x, y], parent, boardPos));
                }
            }

            return(newBoard);
        }