Skip to content

Instantly share code, notes, and snippets.

@wmiller
Created February 3, 2014 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmiller/8792655 to your computer and use it in GitHub Desktop.
Save wmiller/8792655 to your computer and use it in GitHub Desktop.
XML Database AsyncMapBuilder.cs
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