Skip to content

Instantly share code, notes, and snippets.

@strayTrain
Last active February 6, 2017 03:34
Show Gist options
  • Save strayTrain/bde114a5364dacd24d03d116f6eedfaf to your computer and use it in GitHub Desktop.
Save strayTrain/bde114a5364dacd24d03d116f6eedfaf to your computer and use it in GitHub Desktop.
Tilemap definition
using UnityEngine;
using System.Collections;
[System.Serializable]
public struct TilemapSet
{
public string Key;
public GameObject Prefab;
}
[CreateAssetMenu(fileName = "New Tileset", menuName = "Tileset/New", order = 1)]
public class TilemapDefinition : ScriptableObject
{
public TilemapSet[] Tiles;
// This function takes a key and searches for a mathing prefab in the tilemap set.
// Returns null if the key doesn't exist in the set. The check is case insensitive.
public GameObject GetPrefab(string key)
{
GameObject output = null;
for (int i = 0; i < Tiles.Length; i++)
{
// We want the name check to be case insensitive
if (Tiles[i].Key.ToUpper() == key.ToUpper())
{
output = Tiles[i].Prefab;
break;
}
}
return output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment