示例#1
0
        /// <summary>
        /// Finds a path in the tilemap using world coordinates.
        /// </summary>
        public static List <Vector3> FindPath(Tilemap map, Vector3 start, Vector3 goal)
        {
            List <Vector3> result = null;

            List <Vector3Int> path = FindPath(map, map.WorldToCell(start), map.WorldToCell(goal));

            if (path != null)
            {
                result = new List <Vector3>(path.Capacity);

                foreach (Vector3Int v in path)
                {
                    result.Add(map.GetCellCenterWorld(v));
                }
            }

            return(result);
        }
示例#2
0
        void CreateGrid()
        {
            grid = new Node[GridSizeX, GridSizeY];

            var disabled = new List <Vector2Int>
            {
                new Vector2Int(0, 0),
                new Vector2Int(0, 1),
                new Vector2Int(0, 2),
                new Vector2Int(1, 1),
                new Vector2Int(1, 0),
                new Vector2Int(2, 0),
                new Vector2Int(12, 12),
                new Vector2Int(11, 12),
                new Vector2Int(10, 12),
                new Vector2Int(11, 11),
                new Vector2Int(12, 10),
                new Vector2Int(12, 11),
                // Lamps
                new Vector2Int(9, 12),
                new Vector2Int(12, 9)
            };

            this.disabledTiles = disabled.AsReadOnly();

            for (int x = 0; x < GridSizeX; x++)
            {
                for (int y = 0; y < GridSizeY; y++)
                {
                    var pos   = tilemap.GetCellCenterWorld(new Vector3Int(x, y, 0));
                    var state = Enums.TileState.FREE;

                    if (this.disabledTiles.Any(v => v.Equals(new Vector2Int(x, y))))
                    {
                        state = Enums.TileState.DISABLED;
                    }

                    grid[x, y] = new Node(state, pos, x, y);
                }
            }
        }