Ejemplo n.º 1
0
    /// <summary>
    /// 释放
    /// </summary>
    /// <param name="force"></param>
    /// <returns></returns>
    public bool Release(bool force = false)
    {
        bool sucess = false;

        if (CanRelease(force))
        {
            this.m_prefabObj = null;
            this.m_parent    = null;
            if (this.m_objMount != null)
            {
                GameObject.Destroy(this.m_objMount.gameObject);
            }
            this.m_objMount = null;
            Transform tempTs = null;
            if (m_lstInactive != null)
            {
                for (int i = 0, max = m_lstInactive.Count; i < max; i++)
                {
                    tempTs = m_lstInactive[i];
                    if (null == tempTs)
                    {
                        continue;
                    }
                    GameObject.Destroy(m_lstInactive[i].gameObject);
                }
            }

            if (m_lstActive != null)
            {
                for (int i = 0, max = m_lstActive.Count; i < max; i++)
                {
                    tempTs = m_lstActive[i];
                    if (null == tempTs)
                    {
                        continue;
                    }
                    GameObject.Destroy(m_lstActive[i].gameObject);
                }
            }

            if (null != cloneTs)
            {
                GameObject.Destroy(cloneTs.gameObject);
            }
            this.m_lstActive.Clear();
            this.m_lstInactive.Clear();
            m_state = ObjPoolState.Release;
            PrintMessage("ObjPoot {0} Change to sate {1}", m_sPoolName, m_state);
        }
        return(sucess);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 切换状态
    /// </summary>
    /// <param name="state"></param>
    private void ChangeState(ObjPoolState state)
    {
        if (m_state == ObjPoolState.Release)
        {
            return;
        }
        if (m_state != state)
        {
            bool setSuccess = true;
            switch (state)
            {
            case ObjPoolState.Active:
            {
                m_fLasetActiveTimeStamp = PoolTimeStamp;
            }
            break;

            case ObjPoolState.Idle:
            {
                m_fIdleStatusStartTimeStamp = PoolTimeStamp;
                HandleIdle();
                PrintMessage("ObjPoot {0} Change to sate {1}", m_sPoolName, m_state);
            }
            break;

            case ObjPoolState.Release:
            {
                setSuccess = Release();
            }
            break;
            }
            if (setSuccess)
            {
                m_state = state;
            }
        }
    }