Example #1
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);
        }
Example #2
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);
        }
Example #3
0
        private bool InitGameObject(GameObjectTag tag, out GameObject result)
        {
            result = null;
            //Get Asset from loaded AssetMap
            GameObject asset = null;

            if (m_assetMap.ContainsKey(tag.assetPath))
            {
                asset = m_assetMap[tag.assetPath];
            }
            else
            {
                asset = Resources.Load <GameObject>(tag.assetPath);
            }
            if (asset == null)
            {
                Debug.Log("Asset error");
                return(false);
            }

            //Init a GameObject
            result = GameObject.Instantiate(asset);
            result.transform.SetParent(tag.collectionParent.transform, false);
            result.SetActive(false);
            result.name = tag.name;
            return(true);
        }
Example #4
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);
        }
Example #5
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);
            }
        }
Example #6
0
 public void Clear(GameObjectTag tag)
 {
 }
Example #7
0
 public bool Collect(GameObjectTag tag, GameObject obj)
 {
     return(Collect(tag, obj.GetInstanceID()));
 }