public void DeleteTile(Vector3 position) { if (!GetTiles().ContainsKey(position.ToVector2IntXZ())) { return; } QuadTile tile = GetTiles()[position.ToVector2IntXZ()]; GetTiles().Remove(position.ToVector2IntXZ()); DestroyImmediate(tile.gameObject); }
public void AddTile(Vector3 position, QuadTileData brush, float height) { if (GetTiles().ContainsKey(position.ToVector2IntXZ())) { ReplaceTile(position, brush, height); return; } QuadTile newTile = Instantiate(tilePrefab, position, tilePrefab.transform.rotation, transform); newTile.Init(brush, height); newTile.gameObject.SetLayerRecursively(LayerMask.NameToLayer("Ignore Editor")); GetTiles().Add(position.ToVector2IntXZ(), newTile); }
public List <QuadTile> GetTilesInRange(QuadTile start, int range, float stepHeightLimit, bool useRoughness) { ResetPathfindingData(); List <QuadTile> possibleTiles = new List <QuadTile>(); Queue <QuadTile> frontier = new Queue <QuadTile>(); frontier.Enqueue(start); start.pathFindingData.visited = true; while (frontier.Count > 0) { frontier = new Queue <QuadTile>(frontier.OrderBy(x => x.GetChainValue(0, useRoughness))); QuadTile current = frontier.Dequeue(); foreach (var neighbor in Neighbors(current.transform.position.ToVector2IntXZ())) { if (neighbor.pathFindingData.visited || Math.Abs(neighbor.height - current.height) > stepHeightLimit) { continue; } frontier.Enqueue(neighbor); neighbor.pathFindingData.visited = true; neighbor.pathFindingData.cameFrom = current; Debug.DrawLine(neighbor.transform.position, current.transform.position, Color.blue, 2f); possibleTiles.Add(neighbor); } } return(possibleTiles.Where(x => { int chainValue = x.GetChainValue(-start.pathFindingData.cost, useRoughness); return chainValue <= range && chainValue > 0; }).ToList()); }
public PathfindingData(bool visited, int cost) { this.visited = visited; this.cost = cost; cameFrom = null; }