public static void Preload(string assetName, NodeObject.Type type) { Dictionary <string, GameObject> dict = TypeOfDictionary(type); if (!dict.ContainsKey(assetName)) { dict.Add(assetName, PrefabFromResources(assetName, type)); } }
private static string TypeOfResourceFolder(NodeObject.Type type) { switch (type) { case NodeObject.Type.Gatherable: return(PREF_FOLDER_GATHERABLES); case NodeObject.Type.Creature: return(PREF_FOLDER_CREATURES); default: return(null); } }
private static Dictionary <string, GameObject> TypeOfDictionary(NodeObject.Type type) { switch (type) { case NodeObject.Type.Gatherable: return(gatherablePrefabs); case NodeObject.Type.Creature: return(creaturePrefabs); default: return(null); } }
internal static Dictionary <string, GameObject> creaturePrefabs = new Dictionary <string, GameObject>(); // object pool public static GameObject NewObject(string assetName, NodeObject.Type type, Vector3 position, Transform childOf = null) { Dictionary <string, GameObject> dict = TypeOfDictionary(type); GameObject prefab; // attempt to get one from the dictionary if (dict.ContainsKey(assetName)) { prefab = dict[assetName]; } else { // get it from resources and add it to the dictionary prefab = PrefabFromResources(assetName, type); dict.Add(assetName, prefab); } return(Instantiate(prefab, position, new Quaternion())); }
private static GameObject PrefabFromResources(string assetName, NodeObject.Type type) { return((GameObject)Resources.Load(TypeOfResourceFolder(type) + "/pref_" + assetName, typeof(GameObject))); }
public static void ClearTypeOf(NodeObject.Type type) { }