public void SetCamState(SCameraState State)
    {
        _camState = State;
        mMainCamera.backgroundColor      = State.mBackgroundColor;
        _camera.TargetTransform.position = State.mTargetPosition;
        _camera.TargetTransform.rotation = State.mTargetRotation;
        _camera.transform.localPosition  = State.mCamLocalPosition;
        _camera.transform.localRotation  = State.mCamLocalRotation;

        mMainCamera.nearClipPlane = State.mNearClip;
        mMainCamera.farClipPlane  = State.mFarClip;

        if (State.mViewMode == ECameraViewMode.CVM_ORTHO)
        {
            mMainCamera.orthographic     = true;
            mMainCamera.orthographicSize = State.mFOV;
        }
        else
        {
            mMainCamera.orthographic = false;
            mMainCamera.fieldOfView  = State.mFOV;
        }
    }
Esempio n. 2
0
    private void _OnClickEdgeSetView(EViewDirection ViewDirection)
    {
        _viewDirection = ViewDirection;
        _OnClickPrimitive(_selectedPrimID, false);

        for (int i = 0; i < 4; ++i)
        {
            if (i == (int)ViewDirection)
            {
                mUI.SetToolbarButtonHighlight(_tbbView[i], CToolkitUI.EButtonHighlight.SELECTED);
            }
            else
            {
                mUI.SetToolbarButtonHighlight(_tbbView[i], CToolkitUI.EButtonHighlight.NOTHING);
            }
        }

        /*
         * Quaternion rotation = Quaternion.AngleAxis(0.0f, Vector3.up);
         * if (ViewDirection == EViewDirection.VD_RIGHT) rotation = Quaternion.AngleAxis(270.0f, Vector3.up);
         * else if (ViewDirection == EViewDirection.VD_BACK) rotation = Quaternion.AngleAxis(180.0f, Vector3.up);
         * else if (ViewDirection == EViewDirection.VD_LEFT) rotation = Quaternion.AngleAxis(90.0f, Vector3.up);
         * _modelGob.transform.rotation = rotation;
         */

        GameObject.Destroy(_modelGob);
        _modelGob = _vectorModel.CreateGameObject(ViewDirection);
        _modelGob.transform.SetParent(_sceneGraph.transform);
        _modelGob.GetComponent <MeshRenderer>().material.SetColor("_FloorColor", _floorColour);

        _camState = CGame.CameraManager.GetCamState();
        if (_camState.mViewMode == ECameraViewMode.CVM_GAME)
        {
            _camState.SetViewGame(ViewDirection);
            CGame.CameraManager.SetCamState(_camState);
        }
    }
Esempio n. 3
0
 public override void Hide()
 {
     _camState = CGame.CameraManager.GetCamState();
     _sceneGraph.SetActive(false);
 }
Esempio n. 4
0
    public override void Init(CAssetToolkit Toolkit)
    {
        base.Init(Toolkit);

        mPrimaryContent = mUI.CreateElement(Toolkit.mPrimaryContent, "modelEditor");
        mUI.AddLayout(mPrimaryContent, -1, -1, 1.0f, 1.0f);
        mUI.AddVerticalLayout(mPrimaryContent);
        mPrimaryContent.GetComponent <VerticalLayoutGroup>().spacing = 4.0f;

        GameObject toolbar = mUI.CreateElement(mPrimaryContent, "toolbarView");

        mUI.AddLayout(toolbar, -1, 48, 1.0f, 0.0f);
        mUI.AddImage(toolbar, mUI.WindowPanelBackground);
        mUI.AddHorizontalLayout(toolbar);
        toolbar.GetComponent <HorizontalLayoutGroup>().spacing = 4;

        _tbbSave = mUI.CreateToolbarButton(toolbar, "Save", mUI.SaveImage, _Save);
        //mUI.CreateToolbarButton(toolbar, "Revert", mUI.SaveImage);
        mUI.CreateToolbarSeparator(toolbar);

        _tbbCamGame = mUI.CreateToolbarButton(toolbar, "Game", mUI.CompanyImage, () =>
        {
            _camState.SetViewGame(_viewDirection);
            CGame.CameraManager.SetCamState(_camState);
            mUI.SetToolbarButtonHighlight(_tbbCamGame, CToolkitUI.EButtonHighlight.SELECTED);
            mUI.SetToolbarButtonHighlight(_tbbCamFree, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamSide, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamTop, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamFront, CToolkitUI.EButtonHighlight.NOTHING);
        });

        _tbbCamFree = mUI.CreateToolbarButton(toolbar, "Free", mUI.CompanyImage, () =>
        {
            _camState = CGame.CameraManager.GetCamState();
            _camState.SetViewFree();
            CGame.CameraManager.SetCamState(_camState);
            mUI.SetToolbarButtonHighlight(_tbbCamGame, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamFree, CToolkitUI.EButtonHighlight.SELECTED);
            mUI.SetToolbarButtonHighlight(_tbbCamSide, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamTop, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamFront, CToolkitUI.EButtonHighlight.NOTHING);
        });

        _tbbCamSide = mUI.CreateToolbarButton(toolbar, "Side", mUI.CompanyImage, () =>
        {
            _camState.SetOrthographic(EOrhtoView.OV_LEFT);
            CGame.CameraManager.SetCamState(_camState);
            mUI.SetToolbarButtonHighlight(_tbbCamGame, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamFree, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamSide, CToolkitUI.EButtonHighlight.SELECTED);
            mUI.SetToolbarButtonHighlight(_tbbCamTop, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamFront, CToolkitUI.EButtonHighlight.NOTHING);
        });

        _tbbCamTop = mUI.CreateToolbarButton(toolbar, "Top", mUI.CompanyImage, () =>
        {
            _camState.SetOrthographic(EOrhtoView.OV_TOP);
            CGame.CameraManager.SetCamState(_camState);
            mUI.SetToolbarButtonHighlight(_tbbCamGame, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamFree, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamSide, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamTop, CToolkitUI.EButtonHighlight.SELECTED);
            mUI.SetToolbarButtonHighlight(_tbbCamFront, CToolkitUI.EButtonHighlight.NOTHING);
        });

        _tbbCamFront = mUI.CreateToolbarButton(toolbar, "Front", mUI.CompanyImage, () =>
        {
            _camState.SetOrthographic(EOrhtoView.OV_FRONT);
            CGame.CameraManager.SetCamState(_camState);
            mUI.SetToolbarButtonHighlight(_tbbCamGame, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamFree, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamSide, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamTop, CToolkitUI.EButtonHighlight.NOTHING);
            mUI.SetToolbarButtonHighlight(_tbbCamFront, CToolkitUI.EButtonHighlight.SELECTED);
        });

        mUI.CreateToolbarSeparator(toolbar);
        _tbbShowScale = mUI.CreateToolbarButton(toolbar, "Show Scale", mUI.BrushImage, _OnShowScale);
        mUI.SetToolbarButtonHighlight(_tbbShowScale, CToolkitUI.EButtonHighlight.SELECTED);
        mUI.CreateToolbarSeparator(toolbar);
        _tbbLocal = mUI.CreateToolbarButton(toolbar, "Local", mUI.SaveImage, _OnGlobalLocalClicked);
        mUI.CreateToolbarSeparator(toolbar);
        _tbbToolMove = mUI.CreateToolbarButton(toolbar, "Move", mUI.SaveImage, () => _SetTool(ETool.TRANSLATE));
        //mUI.CreateToolbarButton(toolbar, "Rotate", mUI.SaveImage, () => _SetTool(ETool.ROTATE));
        //mUI.CreateToolbarButton(toolbar, "Scale", mUI.SaveImage, () => _SetTool(ETool.SCALE));
        _tbbToolVertex    = mUI.CreateToolbarButton(toolbar, "Vertex", mUI.SaveImage, () => _SetTool(ETool.VERTEX));
        _tbbToolEdgePaint = mUI.CreateToolbarButton(toolbar, "Edge Paint", mUI.SaveImage, () => _SetTool(ETool.EDGE));

        mUI.SetToolbarButtonHighlight(_tbbToolMove, CToolkitUI.EButtonHighlight.SELECTED);

        GameObject hSplit = mUI.CreateElement(mPrimaryContent, "horzLayout");

        mUI.AddLayout(hSplit, -1, -1, 1.0f, 1.0f);
        mUI.AddHorizontalLayout(hSplit);
        hSplit.GetComponent <HorizontalLayoutGroup>().spacing = 4;

        GameObject w1 = mUI.CreateElement(hSplit, "split1");

        mUI.AddLayout(w1, 256, -1, 0.0f, 1.0f);
        mUI.AddVerticalLayout(w1);
        //AddImage(w1, Color.red);

        GameObject w2 = mUI.CreateElement(hSplit, "split2");

        mUI.AddLayout(w2, -1, -1, 0.60f, 1.0f);
        mUI.AddVerticalLayout(w2);
        //AddImage(w2, Color.green);

        GameObject w3 = mUI.CreateElement(hSplit, "split3");

        mUI.AddLayout(w3, 300, -1, 0.0f, 1.0f);
        mUI.AddVerticalLayout(w3);
        //AddImage(w3, Color.blue);

        // Split 1
        GameObject w1pContent;
        GameObject w1p = mUI.CreateWindowPanel(w1, out w1pContent, "Tools");

        mUI.AddLayout(w1p, -1, -1, 1.0f, 1.0f);
        //mUI.CreateTextElement(w1pContent, "Information", "text", CToolkitUI.ETextStyle.TS_HEADING);
        //mUI.CreateTextElement(w1pContent, "Testing string");

        mUI.CreateTextElement(w1pContent, "View Direction", "text", CToolkitUI.ETextStyle.TS_HEADING);

        toolbar = mUI.CreateElement(w1pContent, "toolbarView");
        mUI.AddLayout(toolbar, -1, 48, 1.0f, -1);
        mUI.AddImage(toolbar, mUI.WindowPanelBackground);
        mUI.AddHorizontalLayout(toolbar);
        toolbar.GetComponent <HorizontalLayoutGroup>().spacing = 4;

        _tbbView[0] = mUI.CreateToolbarButton(toolbar, "Front", mUI.LevelImage, () => _OnClickEdgeSetView(EViewDirection.VD_FRONT));
        _tbbView[1] = mUI.CreateToolbarButton(toolbar, "Right", mUI.LevelImage, () => _OnClickEdgeSetView(EViewDirection.VD_RIGHT));
        _tbbView[2] = mUI.CreateToolbarButton(toolbar, "Back", mUI.LevelImage, () => _OnClickEdgeSetView(EViewDirection.VD_BACK));
        _tbbView[3] = mUI.CreateToolbarButton(toolbar, "Left", mUI.LevelImage, () => _OnClickEdgeSetView(EViewDirection.VD_LEFT));
        mUI.SetToolbarButtonHighlight(_tbbView[0], CToolkitUI.EButtonHighlight.SELECTED);

        mUI.CreateTextElement(w1pContent, "Tool", "text", CToolkitUI.ETextStyle.TS_HEADING);

        GameObject editor;

        mUI.CreateFieldElement(w1pContent, "Edge Brush", out editor);
        mUI.CreateComboBox(editor, _edgeBrush, _GetBrushComboData, (string Name) => { _edgeBrush = Name; });

        mUI.CreateFieldElement(w1pContent, "Floor Colour", out editor);
        mUI.CreateColorEditor(editor, _floorColour, (Color color) => { _SetFloorColour(color); });
        //mUI.CreateFieldElement(w1pContent, "Translate Snap", out editor); mUI.CreateFloatEditor(editor, _snapSpacingTranslate, (float value) => { _snapSpacingTranslate = value; });
        //mUI.CreateFieldElement(w1pContent, "Rotate Snap", out editor); mUI.CreateFloatEditor(editor, _snapSpacingRotate, (float value) => { _snapSpacingRotate = value; });
        //mUI.CreateFieldElement(w1pContent, "Scale Snap", out editor); mUI.CreateFloatEditor(editor, _snapSpacingScale, (float value) => { _snapSpacingScale = value; });

        mUI.CreateTextElement(w1pContent, "Model Components", "text", CToolkitUI.ETextStyle.TS_HEADING);

        toolbar = mUI.CreateElement(w1pContent, "toolbarView");
        mUI.AddLayout(toolbar, -1, 48, 1.0f, -1);
        mUI.AddImage(toolbar, mUI.WindowPanelBackground);
        mUI.AddHorizontalLayout(toolbar);
        toolbar.GetComponent <HorizontalLayoutGroup>().spacing = 4;

        mUI.CreateToolbarButton(toolbar, "Add", mUI.LevelImage, _OnClickAddComponent);
        mUI.CreateToolbarButton(toolbar, "Duplicate", mUI.LevelImage, _OnClickDuplicateComponent);
        mUI.CreateToolbarButton(toolbar, "Remove", mUI.LevelImage, _OnClickRemoveComponent);

        GameObject scrollContent;
        GameObject scrollV1 = mUI.CreateScrollView(w1pContent, out scrollContent, true);

        mUI.AddLayout(scrollV1, -1, -1, 1.0f, 1.0f);

        CTUITreeView treeView;
        GameObject   treeViewGob = mUI.CreateTreeView(scrollContent, out treeView);

        mUI.AddLayout(treeViewGob, -1, -1, 1.0f, 1.0f);

        _treeViewPrimItem           = treeView.mRootItem.AddItem("Primitives");
        _treeViewPrimItem.mExpanded = true;
        _RebuildComponentTree();

        // Split 2
        GameObject w2pContent;
        GameObject w2p = mUI.CreateWindowPanel(w2, out w2pContent, "Model View");

        mUI.AddLayout(w2p, -1, -1, 1.0f, 1.0f);

        _viewport = mUI.CreateElement(w2pContent, "modelView");
        _viewport.AddComponent <CameraView>();
        _viewport.AddComponent <RawImage>().texture        = mToolkit.mPrimaryRT;
        _viewport.GetComponent <CameraView>().mOnMouseDown = _OnViewportMouseDown;
        _viewport.GetComponent <CameraView>().mOnMouseUp   = _OnViewportMouseUp;
        mUI.AddLayout(_viewport, -1, -1, 1.0f, 1.0f);

        // Split 3
        GameObject w3pContent;
        GameObject w3p = mUI.CreateWindowPanel(w3, out w3pContent, "Properties");

        mUI.AddLayout(w3p, -1, -1, 1.0f, 1.0f);

        mUI.CreateTextElement(w3pContent, "Selected Component", "text", CToolkitUI.ETextStyle.TS_HEADING);

        scrollV1 = mUI.CreateScrollView(w3pContent, out scrollContent, true);
        mUI.AddLayout(scrollV1, -1, -1, 1.0f, 1.0f);
        scrollContent.GetComponent <VerticalLayoutGroup>().spacing = 4;

        _primProps = scrollContent;

        // World Scene
        _sceneGraph = new GameObject("modelEditorRoot");

        _scaleMan = GameObject.Instantiate(CGame.PrimaryResources.Prefabs[7] as GameObject);
        _scaleMan.transform.SetParent(_sceneGraph.transform);
        _scaleMan.transform.localPosition = new Vector3(-1.0f, 0.0f, -3.0f);
        _scaleMan.transform.rotation      = Quaternion.AngleAxis(225, Vector3.up);

        _sceneGraph.SetActive(false);
        _modelGob = _vectorModel.CreateGameObject(_viewDirection);
        _modelGob.transform.SetParent(_sceneGraph.transform);
        _modelGob.GetComponent <MeshRenderer>().material.SetColor("_FloorColor", _floorColour);

        _camState.mBackgroundColor = new Color(0.18f, 0.18f, 0.18f, 1.0f);
        _camState.SetViewGame(EViewDirection.VD_FRONT);
        mUI.SetToolbarButtonHighlight(_tbbCamGame, CToolkitUI.EButtonHighlight.SELECTED);

        _tool = ETool.TRANSLATE;
    }
Esempio n. 5
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);
    }