Пример #1
0
        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));
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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()));
        }
Пример #5
0
 private static GameObject PrefabFromResources(string assetName, NodeObject.Type type)
 {
     return((GameObject)Resources.Load(TypeOfResourceFolder(type) + "/pref_" + assetName, typeof(GameObject)));
 }
Пример #6
0
 public static void ClearTypeOf(NodeObject.Type type)
 {
 }