Created
February 3, 2014 21:20
-
-
Save wmiller/8792655 to your computer and use it in GitHub Desktop.
XML Database AsyncMapBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AsyncMapBuilder : MapBuilder | |
{ | |
protected override void InitMapObjects() | |
{ | |
for (int y = 0; y < Height; ++y) | |
{ | |
for (int x = 0; x < Width; ++x) | |
{ | |
int height = HeightField[y * Width + x]; | |
int tempX = x; | |
int tempY = y; | |
// Get all tiles in the database that match the height | |
TileInfo[] tileInfos = Database.Instance.GetEntries<TileInfo>().Where((info) => info.Height == height).ToArray(); | |
// Instance the tile | |
TileInfo tileInfo = tileInfos[Random.Range(0, tileInfos.Length)]; | |
resourceManager.LoadAssetAsync<GameObject>(tileInfo.PrefabInfoRef.Entry, (prefab) => | |
{ | |
InstantiateMapPrefab(tempX, tempY, MapObjectDepth.Tile, prefab); | |
}); | |
// See if we drop a feature | |
if (tileInfo.PossibleFeatures != null && | |
tileInfo.PossibleFeatures.Length > 0 && | |
Random.Range(0, 100) < tileInfo.FeatureChance) | |
{ | |
// Select a random feature from the tile infos possible features | |
FeatureInfo featureInfo = tileInfo.PossibleFeatures[Random.Range(0, tileInfo.PossibleFeatures.Length)]; | |
resourceManager.LoadAssetAsync<GameObject>(featureInfo.PrefabInfoRef.Entry, (prefab) => | |
{ | |
InstantiateMapPrefab(tempX, tempY, MapObjectDepth.Feature, prefab); | |
}); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment