Example #1
0
            } // end Update

            public GameObject GetGameObject(string name) {
                if (string.IsNullOrEmpty(name)) {
#if __MY_DEBUG__
                    ConsoleTool.SetError(GetType() + "GetGameObject name is null or empty! Name:" + name);
#endif
                    return null;
                } // end if
                Stack<GameObject> objects;
                if (false == objectsMap.TryGetValue(name, out objects)) {
#if __MY_DEBUG__
                    Debug.Log(GetType() + "GetGameObject Name:" + name + " build a pool!");
#endif
                    objects = new Stack<GameObject>();
                    objectsMap[name] = objects;
                } // end if
                GameObject Go = objects.Count > 0 ? objects.Pop() : null;
                if (Go != null) return Go;
                // end if
                GameObject prefab = ResourcesTool.LoadPrefabPool(name);
                if (null == prefab) {
#if __MY_DEBUG__
                    ConsoleTool.SetError(GetType() + "GetGameObject prefab is null! name:" + name);
#endif
                    return null;
                } // end if
                Go = Object.Instantiate(prefab, poolParent);
                Go.name = name;
                return Go;
            } // end GetGameObject