Пример #1
0
        void createGrid()
        {
            Vector2    gridSize  = calcGridSize();
            GameObject hexGridGO = new GameObject("HexGrid");

            board = new Dictionary <Point, TileBehaviour>();

            for (float y = 0; y < gridSize.y; y++)
            {
                float sizeX = gridSize.x;
                if (y % 2 != 0 && (gridSize.x + 0.5) * hexWidth > groundWidth)
                {
                    sizeX--;
                }
                for (float x = 0; x < sizeX; x++)
                {
                    GameObject hex     = (GameObject)Instantiate(Hex);
                    Vector2    gridPos = new Vector2(x, y);
                    hex.transform.position = calcWorldCoord(gridPos);
                    hex.transform.parent   = hexGridGO.transform;
                    TileBehaviour tileB = hex.GetComponent <TileBehaviour>();
                    Spawn         spawn = hex.GetComponent <Spawn>();
                    spawn.Tile = tileB;

                    tileB.tile = new Tile((int)x - (int)(y / 2), (int)y, true);

                    board.Add(tileB.tile.Location, tileB);
                }
            }
            bool equalLineLengths = (gridSize.x + 0.5) * hexWidth <= groundWidth;

            foreach (TileBehaviour tb in board.Values)
            {
                tb.tile.FindNeighbours(board, gridSize, equalLineLengths);
            }

            hexGridGO.transform.parent   = Ground.transform.parent;
            hexGridGO.transform.position = new Vector3(Ground.transform.position.x, Ground.transform.position.y + 0.155f, Ground.transform.position.z);
//            Selection.activeGameObject = hexGridGO;
        }
Пример #2
0
        void FindPath(TileBehaviour tb, Stack <TileBehaviour> path)
        {
            if (tb.tile.WeightWalk == 0)
            {
                tb.Soldier.GetComponent <Util.Abstract.Soldier>().SavePath(path);
                Soldier = tb.Soldier;
                Soldier.GetComponent <Util.Abstract.Soldier>().Destination = this;
                return;
            }
            TileBehaviour min = tb;

            foreach (TileBehaviour neighbour in tb.tile.GetAllNeighbours())
            {
                if (min.tile.WeightWalk > neighbour.tile.WeightWalk)
                {
                    min = neighbour;
                }
            }
            path.Push(min);
            min.ChangeToPath();
            FindPath(min, path);
        }