コード例 #1
0
        /// <summary>
        /// Gets the object from pool.
        /// </summary>
        /// <returns>
        /// A GameObject if the object was found in the object pool. Null otherwise.
        /// </returns>
        /// <param name='objectType'>
        /// The search type you want to search for a available object
        /// </param>
        /// <param name='typeString'>
        /// Search string based on the object type.
        /// </param>
        /// <param name='activateDirect'>
        /// Set to true if the object should be activated directly. Usefull if you want to place the object before it becomes active.
        /// </param>
        /// <param name='isVisible'>
        /// Set to true if the object should be visible directly. Set to false if it should be invisible from the start.
        /// </param>
        public GameObject GetObjectFromPool(GetObjectByType objectType, string typeString, bool activateDirect, bool isVisible, string callOnMethodWhenCollected)
        {
            GameObject objectFromPool = GetObjectFromPool(objectType, typeString, activateDirect, callOnMethodWhenCollected);

            ToggleVisible(objectFromPool, isVisible);
            return(objectFromPool);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves a object from the object pool.
        /// </summary>
        /// <param name="objectType">The search type you want to search for a available object.</param>
        /// <param name="typeString">Search string based on the object type.</param>
        /// <param name="activateDirect">Set to true if the object should be activated directly. Usefull if you want to place the object before it becomes active.</param>
        /// <returns>A GameObject if the object was found in the object pool. Null otherwise.</returns>
        public GameObject GetObjectFromPool(GetObjectByType objectType, string typeString, bool activateDirect, string callOnMethodWhenCollected)
        {
            List <GameObject> tempList = FindObjectPoolList(objectType, typeString);

            if (tempList != null && tempList.Count > 0)
            {
                int        index            = 0; //(tempList.Count - 1);
                int        listIndex        = GetListIndex(tempList);
                GameObject returnGameObject = tempList[index];
                tempList.RemoveAt(index);
                StartCoroutine(CheckForObjectPoolCount(tempList, listIndex));

                if (activateDirect == true)
                {
                    ActivatetObject(returnGameObject);
                }
                if (returnGameObject != null && string.Equals(callOnMethodWhenCollected, string.Empty) == false)
                {
                    returnGameObject.SendMessage(callOnMethodWhenCollected, SendMessageOptions.DontRequireReceiver);
                }

                return(returnGameObject);
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Returns and adds a object to the existing object pool.
        /// </summary>
        /// <param name="objectType">The search type you want to search for existing object pool.</param>
        /// <param name="currentGameObject">GameObject to search for.</param>
        /// <returns>True if the object was successfully added to the object pool. False otherwise.</returns>
        public bool ReturnObjectToObjectPool(GetObjectByType objectType, GameObject currentGameObject)
        {
            if (currentGameObject == null)
            {
                return(false);
            }

            int internalListCount = ObjectPoolList.Count;
            int index             = 0;

            while (index < internalListCount)
            {
                string currentObjectTypeString = string.Empty;
                string returningObjectString   = string.Empty;

                if (ObjectPoolList[index] != null)
                {
                    switch (objectType)
                    {
                    case GetObjectByType.Tag:
                        currentObjectTypeString = ObjectPoolList[index].tag;
                        returningObjectString   = currentGameObject.tag;
                        break;

                    case GetObjectByType.Name:
                        currentObjectTypeString = ObjectPoolList[index].name;
                        returningObjectString   = currentGameObject.name;
                        break;

                    case GetObjectByType.GameObject:
                        currentObjectTypeString = ObjectPoolList[index].ToString();
                        returningObjectString   = currentGameObject.ToString();
                        break;

                    default:
                        return(false);
                    }

                    if (string.Equals(currentObjectTypeString, returningObjectString) == true)
                    {
                        if (currentGameObject != null)
                        {
                            DeactivateObject(currentGameObject);
                            m_internalObjectPool[index].Add(currentGameObject);
                            return(true);
                        }
                    }
                }
                index += 1;
            }

            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Performs a search operation to find a matching object pool.
        /// </summary>
        /// <param name="objectType">The type of search</param>
        /// <param name="typeString">Search string based on the type given above.</param>
        /// <returns>Returns the object list which belongs to the searchewd object.</returns>
        private List <GameObject> FindObjectPoolList(GetObjectByType objectType, string typeString)
        {
            int internalListCount = m_internalObjectPool.Count;
            int index             = 0;

            while (index < internalListCount)
            {
                string currentObjectTypeString = string.Empty;

                if (ObjectPoolList[index] != null)
                {
                    switch (objectType)
                    {
                    case GetObjectByType.Tag:
                        currentObjectTypeString = ObjectPoolList[index].tag;
                        break;

                    case GetObjectByType.Name:
                        currentObjectTypeString = ObjectPoolList[index].name;
                        break;

                    case GetObjectByType.GameObject:
                        currentObjectTypeString = ObjectPoolList[index].name;
                        break;

                    default:
                        return(null);
                    }

                    if (string.Equals(currentObjectTypeString, typeString) == true)
                    {
                        return(m_internalObjectPool[index]);
                    }
                }

                index += 1;
            }

            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Performs a search operation to find a matching object pool.
        /// </summary>
        /// <param name="objectType">The type of search</param>
        /// <param name="typeString">Search string based on the type given above.</param>
        /// <returns>Returns the object list which belongs to the searchewd object.</returns>
        private List<GameObject> FindObjectPoolList(GetObjectByType objectType, string typeString)
        {
            int internalListCount	= m_internalObjectPool.Count;
            int index				= 0;
            while(index < internalListCount)
            {
                string currentObjectTypeString = string.Empty;

                if(ObjectPoolList[index] != null)
                {
                    switch (objectType)
                    {
                    case GetObjectByType.Tag:
                        currentObjectTypeString = ObjectPoolList[index].tag;
                        break;
                    case GetObjectByType.Name:
                        currentObjectTypeString = ObjectPoolList[index].name;
                        break;
                    case GetObjectByType.GameObject:
                        currentObjectTypeString = ObjectPoolList[index].name;
                        break;
                    default:
                        return null;
                    }

                    if (string.Equals(currentObjectTypeString, typeString) == true)
                        return m_internalObjectPool[index];
                }

                index += 1;
            }

            return null;
        }
コード例 #6
0
        /// <summary>
        /// Returns and adds a object to the existing object pool.
        /// </summary>
        /// <param name="objectType">The search type you want to search for existing object pool.</param>
        /// <param name="currentGameObject">GameObject to search for.</param>
        /// <returns>True if the object was successfully added to the object pool. False otherwise.</returns>
        public bool ReturnObjectToObjectPool(GetObjectByType objectType, GameObject currentGameObject)
        {
            if (currentGameObject == null)
                return false;

            int internalListCount	= ObjectPoolList.Count;
            int index				= 0;
            while(index < internalListCount)
            {
                string currentObjectTypeString = string.Empty;
                string returningObjectString = string.Empty;

                if(ObjectPoolList[index] != null)
                {
                    switch (objectType)
                    {
                    case GetObjectByType.Tag:
                        currentObjectTypeString = ObjectPoolList[index].tag;
                        returningObjectString = currentGameObject.tag;
                        break;
                    case GetObjectByType.Name:
                        currentObjectTypeString = ObjectPoolList[index].name;
                        returningObjectString = currentGameObject.name;
                        break;
                    case GetObjectByType.GameObject:
                        currentObjectTypeString = ObjectPoolList[index].ToString();
                        returningObjectString = currentGameObject.ToString();
                        break;
                    default:
                        return false;
                    }

                    if (string.Equals(currentObjectTypeString, returningObjectString) == true)
                    {
                        if(currentGameObject != null)
                        {
                            DeactivateObject(currentGameObject);
                            m_internalObjectPool[index].Add(currentGameObject);
                            return true;
                        }
                    }
                }
                index += 1;
            }

            return false;
        }
コード例 #7
0
 /// <summary>
 /// Gets the object from pool.
 /// </summary>
 /// <returns>
 /// A GameObject if the object was found in the object pool. Null otherwise.
 /// </returns>
 /// <param name='objectType'>
 /// The search type you want to search for a available object
 /// </param>
 /// <param name='typeString'>
 /// Search string based on the object type.
 /// </param>
 /// <param name='activateDirect'>
 /// Set to true if the object should be activated directly. Usefull if you want to place the object before it becomes active.
 /// </param>
 /// <param name='isVisible'>
 /// Set to true if the object should be visible directly. Set to false if it should be invisible from the start.
 /// </param>
 public GameObject GetObjectFromPool(GetObjectByType objectType, string typeString, bool activateDirect, bool isVisible, string callOnMethodWhenCollected)
 {
     GameObject objectFromPool = GetObjectFromPool(objectType, typeString, activateDirect, callOnMethodWhenCollected);
     ToggleVisible(objectFromPool, isVisible);
     return objectFromPool;
 }
コード例 #8
0
        /// <summary>
        /// Retrieves a object from the object pool.
        /// </summary>
        /// <param name="objectType">The search type you want to search for a available object.</param>
        /// <param name="typeString">Search string based on the object type.</param>
        /// <param name="activateDirect">Set to true if the object should be activated directly. Usefull if you want to place the object before it becomes active.</param>
        /// <returns>A GameObject if the object was found in the object pool. Null otherwise.</returns>
        public GameObject GetObjectFromPool(GetObjectByType objectType, string typeString, bool activateDirect, string callOnMethodWhenCollected)
        {
            List<GameObject> tempList = FindObjectPoolList(objectType, typeString);

            if (tempList != null && tempList.Count > 0)
            {
                int index = 0; //(tempList.Count - 1);
                int listIndex = GetListIndex(tempList);
                GameObject returnGameObject = tempList[index];
                tempList.RemoveAt(index);
                StartCoroutine(CheckForObjectPoolCount(tempList, listIndex));

                if (activateDirect == true)
                    ActivatetObject(returnGameObject);
                if (returnGameObject != null && string.Equals(callOnMethodWhenCollected, string.Empty) == false)
                    returnGameObject.SendMessage(callOnMethodWhenCollected, SendMessageOptions.DontRequireReceiver);

                return returnGameObject;
            }

            return null;
        }