Ejemplo n.º 1
0
    /// <summary>
    /// 释放实体
    /// </summary>
    /// <param name="objev"></param>
    /// <returns></returns>
    public static bool ReleaseEntity(EntityView objev)
    {
        if (objev == null)
        {
            Trace.LogError("释放实体时找不到目标实体!");
            return(false);
        }

        if (m_friendPlayerList.Count > 0)
        {
            if (m_friendPlayerListIndex >= 0 && m_friendPlayerListIndex < m_friendPlayerList.Count && objev.ID == m_friendPlayerList[m_friendPlayerListIndex])
            {
                if (SoldierCamera.MainInstance() != null && EntityFactory.MainHeroView != null && EntityFactory.MainHeroView.gameObject != null)
                {
                    SoldierCamera.MainInstance <SoldierCamera>().SwitchLookAtSolider(EntityFactory.MainHeroView); //切回到主角
                }
            }

            if (m_friendPlayerList.Contains((uint)objev.ID))
            {
                m_friendPlayerList.Remove((uint)objev.ID);
            }
        }

        ENTITY_ID   id   = objev.ID;
        ENTITY_TYPE type = objev.Type;

        m_NeedToLoadEntity.Remove(id);
        EntityFactory.Instance.m_entityContainer.Remove(ref objev);

        bool isHero = objev.IsHero;

        // 主角特殊处理一下
        if (isHero)
        {
            Initialize.Instance.ResetGameManager();
            MainHero     = null;
            MainHeroView = null;
            MainHeroID   = 0;
        }
        LogicDataCenter.warMinimapDataManager.RemoveObject(objev);
        LogicDataCenter.warOBDataManager.RemoveObject(objev);
        objev.Destroy();

        EntityFactory.Instance.EntityNum--;

        switch (type)
        {
        case ENTITY_TYPE.TYPE_PLAYER_ROLE:  { EntityFactory.Instance.ActorNum--; break; }

        case ENTITY_TYPE.TYPE_MONSTER:      { EntityFactory.Instance.MonsterNum--; break; }

        default: break;
        }

        objev = null;

        if (type == ENTITY_TYPE.TYPE_PLAYER_ROLE)
        {
            if (isHero)
            {
                Trace.Log("释放主角实体对象, id=" + id.ToString() + ", type=" + type.ToString());
            }
            else
            {
                Trace.Log("释放实体对象, id=" + id.ToString() + ", type=" + type.ToString());
            }
        }

        return(true);
    }