示例#1
0
    public bool Init(CStartParams Params)
    {
        mStartParams = Params;

        CLevelAsset level = CGame.AssetManager.GetAsset <CLevelAsset>(Params.mLevelName);

        if (level == null)
        {
            Debug.LogError("Could not load level " + Params.mLevelName);
            return(false);
        }

        _world = new CWorld();

        if (!_world.mScriptManager.Init(Params.mLevelName + CGame.FIBRE_FILE_EXTENSION))
        {
            _world.mScriptManager.Destroy();
            return(false);
        }

        _userWorldView = new CUserWorldView();

        mPrimaryScene = new GameObject("Primary Scene");
        mPrimaryScene.transform.position = Vector3.zero;

        CGame.UIManager.SetupForGameSession();

        SCameraState camState = new SCameraState();

        camState.mBackgroundColor = new Color(0.18f, 0.18f, 0.18f, 1.0f);
        camState.SetViewGame(EViewDirection.VD_FRONT);
        camState.mLockedToMap = true;

        if (Params.mPlayType == EPlayType.SINGLE)
        {
            level.CreateMap(_world.mMap);
            _world.InitCompanies();
            _world.PopulateWithMetaData(level);
            _world.PostInit();
            _world.mMap.GetLevelGOB().transform.SetParent(mPrimaryScene.transform);

            CPlayer userPlayer = _world.GetFirstPlayablePlayer();
            userPlayer.mHumanInput = true;
            mUserPlayerIndex       = userPlayer.mID;

            camState.mBackgroundColor = level.mBackgroundColor;

            //_replay.StartRecording("replay");

            _userSession = new CUserSession(this, _userWorldView);
            _world.mScriptManager.Start(_world);
        }
        else if (Params.mPlayType == EPlayType.LOAD)
        {
            // TODO: Load all state from file.
            // Base map stuff is also saved into file.
            // Session, UI, UserWorldView, World
            //_DeserializeState(CGame.PersistentDataDirectory + CGame.SAVE_DIRECTORY + StateFileName + CGame.SAVE_FILE_EXTENSION);
        }
        else if (Params.mPlayType == EPlayType.HOST)
        {
            mUserPlayerIndex = Params.mUserPlayerIndex;
            // TODO: Load level exactly like singleplayer
            //if (Net.Host(5000)) Debug.Log("Hosting Game");
        }
        else if (Params.mPlayType == EPlayType.CLIENT)
        {
            mUserPlayerIndex = Params.mUserPlayerIndex;
            // TODO: Load level exactly like singleplayer
            // if (Net.Connect(Datastore.mConfig.mHostIP, 5000)) Debug.Log("Joined Game");
        }
        else if (Params.mPlayType == EPlayType.REPLAY)
        {
            mUserPlayerIndex = Params.mUserPlayerIndex;
            // TODO: Load level exactly like singleplayer
            //_DeserializeState(CGame.PersistentDataDirectory + CGame.REPLAYS_DIRECTOY + FileName + CGame.REPLAY_FILE_EXTENSION);
            _replay = new CReplay();
            //_replay.StartPlayback(FileName);
        }

        _userWorldView.Init(this, _world, _userSession, mUserPlayerIndex);
        _simThread = new CSimThread(this);
        camState.mTargetPosition = _world.mPlayers[mUserPlayerIndex].GetSpawnPos().ToWorldVec3();
        CGame.CameraManager.SetCamState(camState);

        /*
         * SDecalInfo decalInfo = new SDecalInfo();
         * decalInfo.mType = CDecal.EDecalType.TEXT;
         * decalInfo.mText = "Paperwork";
         * decalInfo.mSize = new Vector2(1, 1);
         * decalInfo.mPosition = new Vector3(13, 0.1f, 11);
         * decalInfo.mRotation = Quaternion.Euler(90, 0, 0);
         * decalInfo.mColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
         * decalInfo.mVis = CDecal.EDecalVis.LOS;
         * _world.SpawnDecal(0, decalInfo);
         *
         * decalInfo.mType = CDecal.EDecalType.IMAGE;
         * decalInfo.mPosition = new Vector3(13, 0.1f, 14);
         * decalInfo.mSize = new Vector2(4, 4);
         * decalInfo.mRotation = Quaternion.Euler(90, 0, 0);
         * decalInfo.mVisualId = 1;
         * //decalInfo.mColor = new Color(0.5f, 0.5f, 0.5f, 1.0f);
         * _world.SpawnDecal(0, decalInfo);
         *
         * decalInfo.mType = CDecal.EDecalType.TEXT;
         * decalInfo.mText = "Lobby";
         * decalInfo.mSize = new Vector2(0.8f, 0.8f);
         * decalInfo.mPosition = new Vector3(7, 0.1f, 13);
         * decalInfo.mRotation = Quaternion.Euler(90, 90, 0);
         * decalInfo.mColor = new Color(1,1,1,1);
         * decalInfo.mVis = CDecal.EDecalVis.FOW;
         * _world.SpawnDecal(0, decalInfo);
         */

        //_world.SpawnItem(CGame.AssetManager.GetAsset<CItemAsset>("item_couch_test"), new Vector2(10, 6), 0, 0);

        /*
         * for (int i = 0; i < 10; ++i)
         * {
         *      CResume resume = new CResume();
         *      resume.Generate(_world, 1, 1);
         *      CUnit entity = _world.SpawnUnit(0, resume, new Vector2(20, 20), 0);
         * }
         * //*/

        // TODO: Do we need to check a map always has correct spawns for players?
        //_world.SpawnItem(CGame.AssetManager.GetAsset<CItemAsset>("item_spawn"), new Vector2(12, 16), 0, 0);
        //_world.SpawnItem(CGame.AssetManager.GetAsset<CItemAsset>("item_spawn"), new Vector2(21, 16), 0, 1);
        return(true);
    }