Last active
February 6, 2017 03:34
-
-
Save strayTrain/bde114a5364dacd24d03d116f6eedfaf to your computer and use it in GitHub Desktop.
Tilemap definition
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
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