Example #1
0
    /**
     *  进入某场景
     *  \param nSceneID
     *      场景ID/玩家城市id
     *  \param nResID
     *      场景的客户端资源ID
     *
     *  \param nCityLevel
     *      玩家城市等级,如果小于0,表示是普通场景!
     */
    public bool EnterScene(int nSceneID, int nResID, int nCityLevel)
    {
        //LogManager.Log("EnterScene(): int WorldManager");
        //必须在进入场景流程中
        if (GameProcedure.GetActiveProcedure() != GameProcedure.s_ProcEnter)
        {
            LogManager.Log("Must enter scene at ENTER procedure");
            return(false);
        }

        _DBC_SCENE_DEFINE pSceneDef = null;

        //如果是玩家城市
        bool bUserCity = (nCityLevel >= 0);

        if (bUserCity)
        {
            //查找城市场景
            for (int i = 0; i < (int)DBC.COMMON_DBC <_DBC_SCENE_DEFINE> .DataNum; i++)
            {
                _DBC_SCENE_DEFINE pTempSceneDef = SceneDBC.Search_Index_EQU(i);

                //Id和等级相同
                if (pTempSceneDef.nSceneResID == nResID && pTempSceneDef.nCityLevel == nCityLevel)
                {
                    pSceneDef = pTempSceneDef;
                    break;
                }
            }
        }
        else
        {
            //查找场景定义
            pSceneDef = SceneDBC.Search_Index_EQU(nResID);
        }

        if (pSceneDef == null)
        {
            LogManager.LogError("(CWorldManager::EnterScene) Invalid scene ID:" + nResID);
            return(false);
        }

        //首先离开现有的场景
        if (ActiveScene != null)
        {
            //相同的场景
            if (GetActiveSceneID() == nSceneID)
            {
                //LogManager.Log("Enter The Same Scene");
                return(false);
            }

            // 移除寻路轨迹 [9/21/2011 Sun]
            //ClearAllFreeProjTex();

            //删除当前场景
            m_pActiveScene.LeaveScene();

            m_pActiveScene = null;
        }

        m_nActiveSceneID = (short)nSceneID;
        //创建新的场景
        m_pActiveScene = new CScene(pSceneDef, mLoadSceneBehaviour);

        //加载新的场景, 加载静态物体定义
        m_pActiveScene.Initial();

        ////进入场景
        m_pActiveScene.EnterScene();

        m_Station = WORLD_STATION.WS_ENTER;
        ////产生进入场景的事件
        CEventSystem.Instance.PushEvent(GAME_EVENT_ID.GE_SCENE_TRANSED, ActiveScene.GetSceneDefine().szSceneMap);

        return(true);
    }