示例#1
0
    void Start()
    {
        localRotation = bodyTransform.localRotation;

        CursorLocker.onCursorChanged += cursorStateChanged;
        m_cursorIsLocked              = CursorLocker.isLocked();
        CursorLocker.lockCursor();
    }
        public void Start()
        {
            log = new Log(this.GetType().Name);
            log.Debug("Start");

            if (gui == null)
            {
                gui = this.gameObject.AddComponent <MainMenuGui> ();
                gui.UpdateToolbarStock();
                gui.SetVisible(false);
            }

            config = readConfig();

            KspIssue3838Fix.ApplyFix(config.enableExperimentalEditorExtensionsCompatibility);

            editorFSM = (KerbalFSM)Refl.GetValue(EditorLogic.fetch, "\u0001");

            cursorLocker = Application.platform == RuntimePlatform.WindowsPlayer ? new WinCursorLocker() : (CursorLocker) new UnityLocker();

            movementBounds = new Bounds();
            if (EditorDriver.editorFacility == EditorFacility.VAB)
            {
                movementBounds = config.vab.bounds;
            }
            else if (EditorDriver.editorFacility == EditorFacility.SPH)
            {
                movementBounds = config.sph.bounds;
            }
            if (!config.enforceBounds)
            {
                movementBounds = new Bounds(Vector3.zero, Vector3.one * float.MaxValue);
            }

            var restartListener = new EventVoid.OnEvent(this.OnEditorRestart);

            GameEvents.onEditorRestart.Add(restartListener);
            OnCleanup += () => GameEvents.onEditorRestart.Remove(restartListener);

            var partEventListener = new EventData <ConstructionEventType, Part> .OnEvent(this.OnPartEvent);

            GameEvents.onEditorPartEvent.Add(partEventListener);
            OnCleanup += () => GameEvents.onEditorPartEvent.Remove(partEventListener);

            if (config.defaultCamera)
            {
                SwitchMode(false);
                ResetCamera();
            }
        }
示例#3
0
 private void SetCursorState(bool state)
 {
     if (_isLocked == state)
     {
         return;
     }
     _isLocked = state;
     if (_isLocked)
     {
         CursorLocker.LockCursor();
     }
     else
     {
         CursorLocker.UnLockCursor();
     }
 }
示例#4
0
    void Awake()
    {
        if (curslorLocker == false)
        {
            curslorLocker = GetComponent <CursorLocker>();
        }
        if (player == null)
        {
            player = GetComponent <Player>();
        }

        m_Yaw   = transform.rotation.eulerAngles.y;
        m_Pitch = m_PitchControllerTransform.localRotation.eulerAngles.x;

        // accedemos al componente del character ontroller
        m_CharacterController = GetComponent <CharacterController>();
    }
        public void Start()
        {
            Log.SetTitle("this.GetType ().Name");

            Log.Debug("Start");
#if (DEBUG)
            Log.SetLevel(Log.LEVEL.INFO);
            Log.Debug("Start 2");
            gui = null;
#endif

            if (gui == null)
            {
                gui = this.gameObject.AddComponent <MainMenuGui>();
                gui.UpdateToolbarStock();
                gui.SetVisible(false);
            }

            readConfig();

            // KspIssue3838Fix.ApplyFix (config.enableExperimentalEditorExtensionsCompatibility);

            //editorFSM = (KerbalFSM)Refl.GetValue (EditorLogic.fetch, "\u0001");
            //Log.Info ("editorFSM: " + editorFSM.ToString ());

            cursorLocker = Application.platform == RuntimePlatform.WindowsPlayer ? new WinCursorLocker() : (CursorLocker) new UnityLocker();



            var restartListener = new EventVoid.OnEvent(this.OnEditorRestart);
            GameEvents.onEditorRestart.Add(restartListener);
            OnCleanup += () => GameEvents.onEditorRestart.Remove(restartListener);

            var partEventListener = new EventData <ConstructionEventType, Part> .OnEvent(this.OnPartEvent);

            GameEvents.onEditorPartEvent.Add(partEventListener);
            OnCleanup += () => GameEvents.onEditorPartEvent.Remove(partEventListener);

            UpdateForEditor();
        }
        public void Start()
        {
            Log.SetTitle ("this.GetType ().Name");

            Log.Debug ("Start");
            #if (DEBUG)
            Log.SetLevel (Log.LEVEL.INFO);
            Log.Debug ("Start");
            gui = null;
            #endif

            if (gui == null) {
                gui = this.gameObject.AddComponent<MainMenuGui> ();
                gui.UpdateToolbarStock ();
                gui.SetVisible (false);

            }

            readConfig ();

            KspIssue3838Fix.ApplyFix (config.enableExperimentalEditorExtensionsCompatibility);

            editorFSM = (KerbalFSM)Refl.GetValue (EditorLogic.fetch, "\u0001");

            cursorLocker = Application.platform == RuntimePlatform.WindowsPlayer ? new WinCursorLocker () : (CursorLocker)new UnityLocker ();

            movementBounds = new Bounds ();
            if (EditorDriver.editorFacility == EditorFacility.VAB) {
                movementBounds = config.vab.bounds;
            } else if (EditorDriver.editorFacility == EditorFacility.SPH) {
                movementBounds = config.sph.bounds;
            }
            if (!config.enforceBounds) {
                movementBounds = new Bounds (Vector3.zero, Vector3.one * float.MaxValue);
            }

            var restartListener = new EventVoid.OnEvent (this.OnEditorRestart);
            GameEvents.onEditorRestart.Add (restartListener);
            OnCleanup += () => GameEvents.onEditorRestart.Remove (restartListener);

            var partEventListener = new EventData<ConstructionEventType, Part>.OnEvent (this.OnPartEvent);
            GameEvents.onEditorPartEvent.Add (partEventListener);
            OnCleanup += () => GameEvents.onEditorPartEvent.Remove (partEventListener);

            if (config.defaultCamera) {
                SwitchMode (false);
                ResetCamera ();
            }
        }
        public void Start()
        {
            Log.SetTitle ("this.GetType ().Name");

            Log.Debug ("Start");
            #if (DEBUG)
            Log.SetLevel (Log.LEVEL.INFO);
            Log.Debug ("Start 2");
            gui = null;
            #endif

            if (gui == null) {
                gui = this.gameObject.AddComponent<MainMenuGui> ();
                gui.UpdateToolbarStock ();
                gui.SetVisible (false);

            }

            readConfig ();

            // KspIssue3838Fix.ApplyFix (config.enableExperimentalEditorExtensionsCompatibility);

            //editorFSM = (KerbalFSM)Refl.GetValue (EditorLogic.fetch, "\u0001");
            //Log.Info ("editorFSM: " + editorFSM.ToString ());

            cursorLocker = Application.platform == RuntimePlatform.WindowsPlayer ? new WinCursorLocker () : (CursorLocker)new UnityLocker ();

            checkMovementBounds ();

            var restartListener = new EventVoid.OnEvent (this.OnEditorRestart);
            GameEvents.onEditorRestart.Add (restartListener);
            OnCleanup += () => GameEvents.onEditorRestart.Remove (restartListener);

            var partEventListener = new EventData<ConstructionEventType, Part>.OnEvent (this.OnPartEvent);
            GameEvents.onEditorPartEvent.Add (partEventListener);
            OnCleanup += () => GameEvents.onEditorPartEvent.Remove (partEventListener);

            if (config.defaultCamera) {
                SwitchMode (false);
                ResetCamera ();
            }
        }
示例#8
0
    private void Update()
    {
        if (CursorLocker.Locked && Input.GetKey(KeyCode.Escape))
        {
            CursorLocker.UnlcokCursor();
        }
        if (!CursorLocker.Locked && (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1)))
        {
            CursorLocker.LockCursor();
        }

        // Set the running and grounded booleans.
        IsRunning  = Input.GetButton("Run");
        IsGrounded = controller.isGrounded;

        // Do the crouch code.
        DoCrouch();

        // Get the direction the player want's to move.
        Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        // This is used a-lot.
        float accel = acceleration * Time.deltaTime;

        // Slow the player down if there is no input.
        if (direction == Vector3.zero && moveSpeed > 0)
        {
            moveSpeed -= accel;
        }
        // There is input, so speed the player up.
        else
        {
            moveSpeed += accel;
        }

        // Set the speed limit for the function the player is currently doing.
        float speedLimit = Speed;

        if (IsRunning)
        {
            speedLimit = RunSpeed;
        }
        if (IsCrouched)
        {
            speedLimit = CrouchSpeed;
        }

        // Enforce the speed limit.
        if (moveSpeed > speedLimit)
        {
            // Get the amount the player is over speeding.
            float delta = moveSpeed - speedLimit;

            if (delta >= deAcceleration * Time.deltaTime)
            {
                moveSpeed -= deAcceleration * Time.deltaTime;
            }
            else
            {
                moveSpeed -= delta;
            }
        }


        // Player can only jump if, they are on the ground, not jumping and not crouching..
        if (Input.GetButtonDown("Jump") && IsGrounded && !IsJumping && !IsCrouched)
        {
            jumpVelocity = JumpSpeed;
            IsJumping    = true;
        }

        // Decay the jump velocity over time to make the jump feel smoother.
        if (IsJumping)
        {
            jumpVelocity -= Time.deltaTime * JumpDecay;
            if (jumpVelocity < 0)
            {
                IsJumping = false;
            }
        }

        // Move the player
        MovePlayer(direction, moveSpeed, jumpVelocity);
    }