Example #1
0
        public static T Instantiate <T>(T prefab, Vector3 position, Quaternion rotation, Transform parent)
            where T : UnityEngine.Object
        {
            if (prefab == null)
            {
                Debug.LogError("[Pool:Instantiate()] -> Prefab cant be null.");
                return(null);
            }

            if (typeof(T).IsSameOrSubclass(typeof(Component)))
            {
                PoolGameObject pool = CreateOrGetPool((prefab as Component).gameObject);
                return(pool.Create(position, rotation, parent).GetComponent <T>());
            }

            if (typeof(T).IsSameOrSubclass(typeof(GameObject)))
            {
                PoolGameObject pool = CreateOrGetPool(prefab as GameObject);
                return(pool.Create(position, rotation, parent) as T);
            }

            return(null);
        }
Example #2
0
        public static T Instantiate <T>(T prefab)
            where T : UnityEngine.Object
        {
            if (prefab == null)
            {
                Debug.LogError("[Pool:Instantiate()] -> Prefab cant be null.");
                return(null);
            }

            if (typeof(T).IsSameOrSubclass(typeof(Component)))
            {
                PoolGameObject pool = CreateOrGetPool((prefab as Component).gameObject);
                return(pool.CreateAs().GetComponent <T>());
            }

            if (typeof(T).IsSameOrSubclass(typeof(GameObject)))
            {
                PoolGameObject pool = CreateOrGetPool(prefab as GameObject);
                return(pool.Create() as T);
            }

            return(null);
        }