Exemplo n.º 1
0
 public void Pack()
 {
     for (int x = 0; x < mapXSize; x++)
     {
         for (int y = 0; y < mapYSize; y++)
         {
             for (int z = 0; z < mapZSize; z++)
             {
                 if (map[x, y, z] != null)
                 {
                     PathfinderTile[,,] neighbors = new PathfinderTile[3, 3, 3];
                     for (int dx = 0; dx < 3; dx++)
                     {
                         for (int dy = 0; dy < 3; dy++)
                         {
                             for (int dz = 0; dz < 3; dz++)
                             {
                                 try {
                                     neighbors[dx, dy, dz] = map[x + dx - 1, y + dy - 1, z + dz - 1];
                                 }
                                 catch (IndexOutOfRangeException ignorable) {}
                             }
                         }
                     }
                     map[x, y, z].Neighbors = neighbors;
                     map[x, y, z].UpdateNeighborMoveTypes();
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public void StartShortestPath(PathfinderTile start, PathfinderTile end)
 {
     this.start         = start;
     this.end           = end;
     shortestPath       = null;
     shortestPathThread = new System.Threading.Thread(ShortestPath);
     shortestPathThread.Start();
 }
Exemplo n.º 3
0
 public void AddTile(PathfinderTile tile)
 {
     if (tileList.Count == 0)
     {
         cost = 0;
     }
     else
     {
         cost += tileList [tileList.Count - 1].GetCost(tile);
     }
     tileList.Add(tile);
 }
Exemplo n.º 4
0
 public static Vector3 GetOnTileUnityPos(PathfinderTile tile)
 {
     int[] indexPos = tile.IndexPos;
     if (tile.TileType == TILE_TYPE.Block)
     {
         return(new Vector3(indexPos[0] * BLOCK_SIZE[0], (indexPos[1] + 1) * BLOCK_SIZE[1], indexPos[2] * BLOCK_SIZE[2]));
     }
     else if (tile.TileType == TILE_TYPE.Ramp_N || tile.TileType == TILE_TYPE.Ramp_E ||
              tile.TileType == TILE_TYPE.Ramp_S || tile.TileType == TILE_TYPE.Ramp_W)
     {
         return(new Vector3(indexPos[0] * BLOCK_SIZE[0], (indexPos[1] + 0.5f) * BLOCK_SIZE[1], indexPos[2] * BLOCK_SIZE[2]));
     }
     else
     {
         return(new Vector3(indexPos[0] * BLOCK_SIZE[0], (indexPos[1] + 1) * BLOCK_SIZE[1], indexPos[2] * BLOCK_SIZE[2]));
     }
 }
Exemplo n.º 5
0
    public float GetCost(PathfinderTile neighborTile)
    {
        ThreadedPathfinder.MOVE_TYPE moveType = ThreadedPathfinder.MOVE_TYPE.None;
        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                for (int z = 0; z < 3; z++)
                {
                    if (neighbors[x, y, z] != null && neighbors[x, y, z].Equals(neighborTile))
                    {
                        moveType = moveTypes[x, y, z];
                    }
                }
            }
        }

        if (moveType == null)           //not a neighbor
        {
            return(float.NaN);
        }
        else if (moveType == ThreadedPathfinder.MOVE_TYPE.Walk)
        {
            return(1f);
        }
        else if (moveType == ThreadedPathfinder.MOVE_TYPE.Walk_Diagonal)
        {
            return(1.5f);
        }
        else if (moveType == ThreadedPathfinder.MOVE_TYPE.Walk_Up)
        {
            return(1.5f);
        }
        else if (moveType == ThreadedPathfinder.MOVE_TYPE.Walk_Down)
        {
            return(0.75f);
        }
        else             //A neighbor not reachable with any known moveTypesment type
        {
            return(float.NaN);
        }
    }
Exemplo n.º 6
0
 public bool Equals(PathfinderTile other)
 {
     return(x == other.x && y == other.y && z == other.z && tileType == other.tileType);
 }
Exemplo n.º 7
0
 public void AddTile(Tile.TILE_TYPE tileType, int[] pos)
 {
     map [pos [0], pos [1], pos [2]] = new PathfinderTile(tileType, pos);
 }
Exemplo n.º 8
0
 //JOGAR NO PATHFINDER
 private void SelectLedge(int index)
 {
     Ledge = PathfinderMap.getLedges()[index];
     transform.position = new Vector3(Ledge.transform.position.x, transform.position.y, 0.0f);
 }