Пример #1
0
    public void MoveByJoystick(float horizontal, float vertical, bool pressed)
    {
        if (Singleton <RoleManager> .Instance.mainCamera == null)
        {
            return;
        }
        if (!pressed)
        {
            if (this.moveType == MoveController.MoveType.Joystick)
            {
                this.moveType = MoveController.MoveType.None;
                this._self.move.StopPath();
                PositionSync.SyncSelfPosition();
            }
            return;
        }
        Vector3 point   = new Vector3(horizontal, 0f, vertical);
        Vector3 forward = Singleton <RoleManager> .Instance.mainCamera.transform.forward;

        forward.y = 0f;
        Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, forward);
        Vector3    vecDir   = rotation * point;

        if (!vecDir.Equals(Vector3.zero))
        {
            this.moveType = MoveController.MoveType.Joystick;
            this._self.move.WalkOnDirection(vecDir);
        }
    }
Пример #2
0
    public void MoveByKeyboard()
    {
        if (UICamera.inputHasFocus)
        {
            return;
        }
        this.bUpState    = (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow));
        this.bDownState  = (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow));
        this.bLeftState  = (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow));
        this.bRightState = (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow));
        if (!this.bUpState && !this.bDownState && !this.bLeftState && !this.bRightState)
        {
            if (this.moveType == MoveController.MoveType.Keyboard)
            {
                this.moveType = MoveController.MoveType.None;
                this._self.move.StopPath();
                PositionSync.SyncSelfPosition();
            }
            return;
        }
        if (Camera.main == null)
        {
            return;
        }
        this.moveType = MoveController.MoveType.Keyboard;
        Vector3 v = Camera.main.transform.rotation * Vector3.forward;

        v.y = 0f;
        v.Normalize();
        float y = 0f;

        if (this.bUpState)
        {
            if (this.bLeftState)
            {
                y = -45f;
            }
            else if (this.bRightState)
            {
                y = 45f;
            }
        }
        else if (this.bDownState)
        {
            if (this.bLeftState)
            {
                y = -135f;
            }
            else if (this.bRightState)
            {
                y = 135f;
            }
            else
            {
                y = 180f;
            }
        }
        else if (this.bLeftState)
        {
            y = -90f;
        }
        else if (this.bRightState)
        {
            y = 90f;
        }
        Matrix4x4 matrix4x = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(new Vector3(0f, y, 0f)), Vector3.one);

        this._self.move.WalkOnDirection(matrix4x.MultiplyVector(v));
    }