Beispiel #1
0
 public TerrainTile GetTerrainTileAt(TerrainTile.Indices tileIndices)
 {
     if (terrainTiles == null)
     {
         Start();
     }
     return(terrainTiles[tileIndices.i, tileIndices.j]);
 }
Beispiel #2
0
        public TerrainTile ReplaceTile(TerrainTile.Indices tileIndices, int prefabIndex)
        {
            if (terrainTiles == null)
            {
                Start();
            }

            return(InstantiateTile(tileIndices, prefabIndex));
        }
Beispiel #3
0
        private TerrainTile InstantiateTile(TerrainTile.Indices tileIndices, int terrainTilePrefabIndex)
        {
            if (tileIndices.i < terrainTiles.GetLength(0) && tileIndices.i >= 0 &&
                tileIndices.j < terrainTiles.GetLength(1) && tileIndices.j >= 0 &&
                terrainTilePrefabIndex < GetTileSet().terrainTilePrefabs.Length&& terrainTilePrefabIndex >= 0)
            {
                GameObject tileObject = Instantiate(GetTileSet().terrainTilePrefabs[terrainTilePrefabIndex], CalculatedPositionForTileAt(tileIndices), Quaternion.identity, transform);

                TerrainTile terrainTileComponent;

                if (terrainTileComponent = tileObject.GetComponent <TerrainTile>())
                {
                    if (terrainTiles[tileIndices.i, tileIndices.j])
                    {
#if UNITY_EDITOR
                        DestroyImmediate(terrainTiles[tileIndices.i, tileIndices.j].gameObject);
#else
                        Destroy(terrainTiles[chunkIndices.i, chunkIndices.j].gameObject);
#endif
                    }
                    terrainTiles[tileIndices.i, tileIndices.j]             = terrainTileComponent;
                    terrainTiles[tileIndices.i, tileIndices.j].indices     = tileIndices;
                    terrainTiles[tileIndices.i, tileIndices.j].prefabIndex = terrainTilePrefabIndex;
                }
                else
                {
                    Debug.Log("InstantiateTile(chunkIndices, prefabIndex); " + tileObject + " has no TerrainTile component.");
                    Destroy(tileObject);
                    return(null);
                }

                return(terrainTileComponent);
            }
            else
            {
                Debug.Log("InstantiateTile(chunkIndices, prefabIndex) arguments out of range.");
                return(null);
            }
        }
Beispiel #4
0
 internal void ResetTilePosition(TerrainTile.Indices tileIndices)
 {
     terrainTiles[tileIndices.i, tileIndices.j].transform.position = CalculatedPositionForTileAt(tileIndices);
 }
Beispiel #5
0
 public Vector3 CalculatedPositionForTileAt(TerrainTile.Indices tileIndices)
 {
     return(new Vector3(transform.position.x - (terrainTiles.GetLength(0) / 2) + tileIndices.i, transform.position.y - (terrainTiles.GetLength(1) / 2) + tileIndices.j));
 }