示例#1
0
        public void DeleteTile(Vector3 position)
        {
            if (!GetTiles().ContainsKey(position.ToVector2IntXZ()))
            {
                return;
            }

            QuadTile tile = GetTiles()[position.ToVector2IntXZ()];

            GetTiles().Remove(position.ToVector2IntXZ());
            DestroyImmediate(tile.gameObject);
        }
示例#2
0
        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);
        }
示例#3
0
        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());
        }
示例#4
0
 public PathfindingData(bool visited, int cost)
 {
     this.visited = visited;
     this.cost    = cost;
     cameFrom     = null;
 }