コード例 #1
0
        public bool TryUse(GameObjectTag tag, out GameObject result)
        {
            result = null;
            if (tag.isError())
            {
                Debug.LogError("Error GameObejct Tag");
                return(false);
            }
            if (!m_gameObjectMap.ContainsKey(tag))
            {
                Debug.LogError("Tag has not LogIn to the Pool");
                return(false);
            }

            foreach (var pair in m_gameObjectMap[tag])
            {
                if (!pair.Value.activeInHierarchy)
                {
                    result = pair.Value;
                }
            }

            if (result == null)
            {
                if (InitGameObject(tag, out result))
                {
                    if (!m_gameObjectMap[tag].ContainsKey(result.GetInstanceID()))
                    {
                        m_gameObjectMap[tag].Add(result.GetInstanceID(), result);
                    }
                }
            }

            return(true);
        }
コード例 #2
0
        public bool Alloc(GameObjectTag tag, int initialNumber = 1)
        {
            if (tag.isError())
            {
                Debug.LogError("Error GameObejct Tag");
                return(false);
            }

            if (!m_gameObjectMap.ContainsKey(tag))
            {
                m_gameObjectMap.Add(tag, new Dictionary <int, GameObject>());
                GameObject tagCollectionObj = new GameObject(string.Format("Tag Name:[{0}]", tag.name));
                tagCollectionObj.transform.SetParent(m_poolGameObject.transform, false);
                tag.collectionParent = tagCollectionObj;
            }

            for (int i = 0; i < initialNumber; i++)
            {
                GameObject preLoadObj = null;
                if (InitGameObject(tag, out preLoadObj))
                {
                    if (!m_gameObjectMap[tag].ContainsKey(preLoadObj.GetInstanceID()))
                    {
                        m_gameObjectMap[tag].Add(preLoadObj.GetInstanceID(), preLoadObj);
                    }
                    Debug.Log(string.Format("PreLoad instanceID:{0}:{1}", preLoadObj.GetInstanceID(), preLoadObj.name));
                }
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Collect specific GameObjectTag in the pool
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public bool Collect(GameObjectTag tag)
        {
            if (tag.isError())
            {
                Debug.LogError("Error GameObejct Tag");
                return(false);
            }

            return(true);
        }
コード例 #4
0
        public bool Collect(GameObjectTag tag, int instanceID)
        {
            if (tag.isError())
            {
                Debug.LogError("Error GameObejct Tag");
                return(false);
            }

            Dictionary <int, GameObject> gameObejcts = m_gameObjectMap[tag];
            GameObject result = null;

            if (gameObejcts.TryGetValue(instanceID, out result))
            {
                result.SetActive(false);
                result.transform.SetParent(tag.collectionParent.transform, false);
                return(true);
            }
            else
            {
                Debug.LogError(string.Format("can not find this instance in map [{0}]", instanceID));
                return(false);
            }
        }