//
        public void launch()
        {
            MainMenu.Instance.init();

            _popup = MainMenu.Instance.popup;

            //goPlayer.transform.position = new Vector3(0, 0.6f, -0.75f);
            //goPlayerCameraRig.transform.position = goPlayer.transform.position;
            Vector3 savedPos = Vector3.zero;
            Vector3 savedRot = Vector2.zero;

            savedPos.x = (VoxelUtils.MAX_CHUNK_UNITS * VoxelUtils.CHUNK_SIZE * .5f);
            savedPos.y = (VoxelUtils.MAX_CHUNK_UNITS * VoxelUtils.CHUNK_SIZE * .5f);
            savedPos.z = (VoxelUtils.MAX_CHUNK_UNITS * VoxelUtils.CHUNK_SIZE * .5f) - 1.0f;
            FlyCam.Instance.setNewInitialPosition(savedPos, savedRot);
            resetCamToStartPos();

            _aEditorTools = new List <EditorTool> ((int)Globals.TOOL.NUM_TOOLS);
            _aEditorTools.Add(new EditorToolLook());
            _aEditorTools.Add(new EditorToolDig());
            _aEditorTools.Add(new EditorToolPaint());
            _aEditorTools.Add(new EditorToolBuild());
            _aEditorTools.Add(new EditorToolProp());
            _aEditorTools.Add(new EditorToolRailgun());

            _curEditorTool = null;

            if (!AppController.Instance.editorIsInOfflineMode)
            {
                int firstLevelId = LevelManager.Instance.getLevelIdByIndex(0);
                teleportToLevelWithId(firstLevelId);
            }

            SceneManager.UnloadSceneAsync(BuildSettings.VWE_SplashScreenScene);
            setMode(AppState.Null, true);

            if (!_popup.isVisible())
            {
                showHelpPopup();
            }
        }
예제 #2
0
        //
        void Update()
        {
            if (_popup.isVisible())
            {
                return;
            }

            _time = Time.realtimeSinceStartup;

            //if (_camCanMove) {
            _move = Input.GetAxis("Horizontal") != 0.0f || Input.GetAxis("Vertical") != 0.0f || Input.GetAxis("Depth") != 0.0f;
            //}

            /*else {
             *      if (!Input.anyKey) { //Input.GetAxis ("Horizontal") == 0.0f && Input.GetAxis ("Vertical") == 0.0f && Input.GetAxis ("Depth") == 0.0f) {
             *              _camCanMove = true;
             *              Input.ResetInputAxes();
             *      }
             * }*/

            if (!_mouseRightIsDown)
            {
                if (Input.GetMouseButtonDown(1))
                {
                    _mouseRightIsDown = true;
                }
            }
            else
            {
                if (Input.GetMouseButtonUp(1))
                {
                    _mouseRightIsDown = false;
                }
            }

            // Looking around with the mouse
            if (_mouseRightIsDown)
            {
                //Debug.Log ("mouse is down - axis x: " + Input.GetAxis ("Mouse X"));
                _player.Rotate(-2f * Input.GetAxis("Mouse Y"), 2f * Input.GetAxis("Mouse X"), 0);
                playerEuler         = _player.eulerAngles;
                playerEuler.z       = 0;
                _player.eulerAngles = playerEuler;
            }

            if (_move)
            {
                if (drawWireframe)
                {
                    //if (_camCanMove) {
                    _player.position += (transform.right * Input.GetAxis("Horizontal") + transform.forward * Input.GetAxis("Vertical") + transform.up * Input.GetAxis("Depth")) * movementSpeed;
                    //}
                }
                else
                {
                    _tempPos  = _player.position;
                    _tempPos += (transform.right * Input.GetAxis("Horizontal")) * movementSpeed;
                    if (_tempPos != _playerPosSave)
                    {
                        _hitColliders = Physics.OverlapSphere(_tempPos, 0.26f, _layermask);
                        if (_hitColliders.Length <= 0)
                        {
                            _player.position = _tempPos;
                        }
                    }

                    _tempPos  = _player.position;
                    _tempPos += (transform.forward * Input.GetAxis("Vertical")) * movementSpeed;
                    if (_tempPos != _playerPosSave)
                    {
                        _hitColliders = Physics.OverlapSphere(_tempPos, 0.26f, _layermask);
                        if (_hitColliders.Length <= 0)
                        {
                            _player.position = _tempPos;
                        }
                    }

                    _tempPos  = _player.position;
                    _tempPos += (transform.up * Input.GetAxis("Depth")) * movementSpeed;
                    if (_tempPos != _playerPosSave)
                    {
                        _hitColliders = Physics.OverlapSphere(_tempPos, 0.26f, _layermask);
                        if (_hitColliders.Length <= 0)
                        {
                            _player.position = _tempPos;
                        }
                    }

                    _playerPosSave = _player.position;

                    // did camera move?

                    /*if (_player.position != _playerPosSave) {
                     *
                     *      _hitColliders = Physics.OverlapSphere (_player.position, 0.26f, _layermask);
                     *      if (_hitColliders.Length > 0) {
                     *              _player.position = _playerPosSave;
                     *              //_move = false;
                     *              Input.ResetInputAxes();
                     *      }
                     *      else {
                     *              _playerPosSave = _player.position;
                     *      }
                     * }*/
                }
            }

            if (_itemCam.enabled)
            {
                _itemCam.transform.position = _myCam.transform.position;
                _itemCam.transform.rotation = _myCam.transform.rotation;
            }

            /*if (_time > _nextDistanceUpdate) {
             *      _nextDistanceUpdate = _time + 1.0f;
             *      LevelEditor.Instance.checkLevelChunkDistances ();
             * }
             * else*/
            if (_time > _nextPosUpdate)
            {
                _nextPosUpdate = _time + 0.5f;
                MainMenu.Instance.setCameraPositionText(_player.position);
            }
        }
        //
        public void customUpdateCheckControls(float time, float timeDelta)
        {
            if (_popup.isVisible())
            {
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    AppController.Instance.hidePopup();
                    if (AppController.Instance.appState == AppState.Null)
                    {
                        startUpPopupCallback(-1);
                    }
                }
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.LeftShift))
                {
                    FlyCam.Instance.drawWireframe = true;
                    itemCamScript.drawWireframe   = true;
                }
                else if (Input.GetKeyUp(KeyCode.LeftShift))
                {
                    FlyCam.Instance.drawWireframe = false;
                    itemCamScript.drawWireframe   = false;
                }

                if (Input.GetKeyDown(KeyCode.F1))
                {
                    showHelpPopup();
                }
                else if (Input.GetKeyDown(KeyCode.Escape))
                {
                    if (AppController.Instance.appState != AppState.Select)
                    {
                        setMode(AppState.Select);
                    }
                }
                else if (Input.GetKeyDown(KeyCode.P))                      // (Input.GetKeyDown (KeyCode.Tab) || Input.GetKeyDown (KeyCode.BackQuote)) {
                {
                    setMode(AppController.Instance.appState == AppState.Play ? AppState.Select : AppState.Play);
                }
                else if (Input.GetKeyDown(KeyCode.H))
                {
                    resetCamToStartPos();
                }
                //else if (Input.GetKeyDown(KeyCode.Alpha0)) {
                //	setMode (AppState.Play);
                //}
                else if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    setMode(AppState.Select);
                }
                else if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    setMode(AppState.Dig);
                }
                else if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    setMode(AppState.Build);
                }
                else if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    setMode(AppState.Paint);
                }
                else if (Input.GetKeyDown(KeyCode.Alpha5))
                {
                    setMode(AppState.Props);
                }
            }

            if (_curEditorTool != null)
            {
                _curEditorTool.customUpdateControls(time, timeDelta);
            }
        }