private void Start()
        {
            if (!PoolManager.instance.Contains(m_PoolName))
            {
                Debug.LogErrorFormat(
                    "Runtime Pre {0} -> The pool named '{1}' is not found.",
                    name,
                    m_PoolName);
                return;
            }

            if (!PoolManager.instance[m_PoolName].AddUnpooledObject(this))
            {
                Debug.LogErrorFormat(
                    "Runtime Pre {0} -> The pool named '{1}' add unpooled object failure.",
                    name,
                    m_PoolName);
                return;
            }

            if (m_DestroyThis)
            {
                RuntimePrePoolObject.Destroy(this);
            }
        }
Example #2
0
        /// <summary>
        /// 加入外部Instance,由RuntimePrePoolObject组件调用
        /// </summary>
        /// <param name="runtime"></param>
        /// <returns></returns>
        internal bool AddUnpooledObject(RuntimePrePoolObject runtime)
        {
            if (!m_PrefabDict.ContainsKey(runtime.m_PrefabName))
            {
                Debug.LogErrorFormat(
                    "{0} -> Add unpooled object '{1}' The prefab is not found.",
                    poolName,
                    runtime.gameObject.name
                    );
                return(false);
            }

            InstanceCollection collection = m_InstanceCollections.Find(c => c.prefabName == runtime.m_PrefabName);

            if (collection == null)
            {
                Debug.LogErrorFormat("{0} -> UNEXPECTED ERROR! May be the pool name was changed at runtime.", poolName);
                return(false);
            }

            collection.Add(runtime.gameObject);
            return(true);
        }