Ejemplo n.º 1
0
    public void LoadAsset()
    {
        CAsset asset = null;

        if (mType == EAssetType.AT_BRUSH)
        {
            asset = new CBrushAsset();
        }
        else if (mType == EAssetType.AT_MODEL)
        {
            asset = new CModelAsset();
        }
        else if (mType == EAssetType.AT_LEVEL)
        {
            asset = new CLevelAsset();
        }
        else if (mType == EAssetType.AT_ITEM)
        {
            asset = new CItemAsset();
        }

        if (asset != null)
        {
            asset.mName     = mName;
            asset.mFileName = mFileName;
            asset.mType     = mType;
            asset.Load();
            mAsset = asset;
        }
        else
        {
            Debug.LogError("Could not load asset: " + mName);
        }
    }
Ejemplo n.º 2
0
        private void OnPlayGame(object argument)
        {
            IsInPlayMode = true;
            m_prePlayModeLevelReference = OpenedLevelAsset;

            UndoRedoModel.IsRecording = false;
            UndoRedoModel.Purge(null);

            CViewportViewModel viewport = GetTool <CViewportViewModel>();

            viewport.IsVisible = true;
            viewport.IsActive  = true;
            viewport.LockMouseCursor();

            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                CWorld world = CEngine.Instance.CurrentWorld;

                m_prePlayModeLevel = new CLevelAsset(world.LoadedLevel, "EditorTempLevel");
                world.StartPlayMode();

                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                }));
            });
        }
Ejemplo n.º 3
0
        public void HandleDrop(object dropData)
        {
            CLevelAsset levelAsset = (CLevelAsset)dropData;

            Stopwatch timer = new Stopwatch();

            timer.Start();
            CLevel newLevel = levelAsset.GetLevel();

            timer.Stop();
            LogUtility.Log("Level deserialize took {0} ms", timer.Elapsed.TotalMilliseconds);
            CEngine.Instance.CurrentWorld.ChangeLevel(levelAsset, newLevel);
        }
Ejemplo n.º 4
0
        private void OnSaveLevelAs(object argument)
        {
            CAssetBrowserViewModel assetBrowser = Instance.GetTool <CAssetBrowserViewModel>();
            string assetPath = assetBrowser.ActiveDirectory;

            CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
            {
                CLevelAsset levelAsset = new CLevelAsset(CEngine.Instance.CurrentWorld.LoadedLevel, "Level", assetPath);
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    assetBrowser.UpdateShownAssets();
                }));
            });
        }
Ejemplo n.º 5
0
    private void _OnClickCreateNewAssetWindow(GameObject Window, EAssetType Type, string AssetName)
    {
        string errorStr;

        if (CGame.AssetManager.IsAssetNameValid(AssetName, out errorStr))
        {
            GameObject.Destroy(Window);

            CTUITreeViewItem treeItem = null;
            CAsset           asset    = null;

            if (Type == EAssetType.AT_MODEL)
            {
                treeItem = _tviModels;
                asset    = new CModelAsset();
            }
            else if (Type == EAssetType.AT_BRUSH)
            {
                treeItem = _tviBrushes;
                asset    = new CBrushAsset();
            }
            else if (Type == EAssetType.AT_LEVEL)
            {
                treeItem = _tviLevels;
                asset    = new CLevelAsset();
            }
            else if (Type == EAssetType.AT_ITEM)
            {
                treeItem = _tviItems;
                asset    = new CItemAsset();
            }

            asset.mName     = AssetName;
            asset.mFileName = CGame.DataDirectory + asset.mName + "." + CAssetManager.ASSET_FILE_EXTENSION;
            Debug.Log("New Asset Path: " + asset.mFileName);
            asset.Save();

            CAssetDeclaration decl = CGame.AssetManager.CreateAssetDeclaration(asset);
            treeItem.AddItem(decl.mName, () => OnClickAsset(decl.mName), () => mToolkit.EditAsset(decl.mName));

            treeItem.RebuildEntireTree();
            mToolkit.EditAsset(AssetName);
        }
        else
        {
            Debug.Log("Asset creation failed: " + errorStr);
        }
    }
Ejemplo n.º 6
0
        private void OnSaveLevel(object arg)
        {
            string assetPath = null;

            CAssetBrowserViewModel assetBrowser = Instance.GetTool <CAssetBrowserViewModel>();

            if (OpenedLevelAsset != null)
            {
                assetPath = OpenedLevelAsset.GetAsset().Path;
                CLevelAsset asset = OpenedLevelAsset.GetAsset();

                CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                {
                    asset.SetLevel(CEngine.Instance.CurrentWorld.LoadedLevel);
                    CAssetRegistry.Instance.SaveAsset(asset);

                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                    {
                        assetBrowser.UpdateShownAssets();
                    }));
                });
            }
        }
Ejemplo n.º 7
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);
    }