Пример #1
0
        public void Should_recall_first_command_with_a_specific_command_when_pressing_Tab()
        {
            //Arrange
            var input             = new[] { ConsoleKey.T, ConsoleKey.W, ConsoleKey.O, ConsoleKey.Tab, ConsoleKey.Enter };
            var consoleManager    = new FakeConsoleManager(new FakeKeyInputEngine(input));
            var console           = new TestConsole(consoleManager);
            var cancellationToken = new CancellationToken();
            var inputInstance     = new InputInstance(console, Constants.Prompt, null, cancellationToken);
            var selection         = new CommandTreeNode <string>(new[]
            {
                new CommandTreeNode <string>("First", "One"),
                new CommandTreeNode <string>("Second", "Two", new []
                {
                    new CommandTreeNode <string>("FirstSub", "SubOne"),
                    new CommandTreeNode <string>("SecondSub", "SubTwo"),
                    new CommandTreeNode <string>("LastSub", "SubX"),
                }),
                new CommandTreeNode <string>("Last", "x")
            });

            //Act
            var r = inputInstance.ReadLine(selection, true);

            //Assert
            var match = selection.Subs.ToArray()[1];

            Assert.That(r, Is.EqualTo(match.Key));
            Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + match.Value));
        }
Пример #2
0
        public void Should_recall_first_sub_command_when_matching_a_sub_part_with_similar_root_name_pressing_Tab()
        {
            //Arrange
            var input             = new[] { ConsoleKey.T, ConsoleKey.W, ConsoleKey.O, ConsoleKey.Spacebar, ConsoleKey.F, ConsoleKey.Tab, ConsoleKey.Enter };
            var consoleManager    = new FakeConsoleManager(new FakeKeyInputEngine(input));
            var console           = new TestConsole(consoleManager);
            var cancellationToken = new CancellationToken();
            var inputInstance     = new InputInstance(console, Constants.Prompt, null, cancellationToken);
            var match             = new CommandTreeNode <string>("FirstSub", "SubOne");
            var selection         = new CommandTreeNode <string>(new[]
            {
                new CommandTreeNode <string>("First", "One"),
                new CommandTreeNode <string>("Second", "Two", new []
                {
                    match,
                    new CommandTreeNode <string>("SecondSub", "SubTwo"),
                    new CommandTreeNode <string>("LastSub", "SubX"),
                }),
                new CommandTreeNode <string>("SecondOther", "TwoOther"),
                new CommandTreeNode <string>("Last", "x")
            });

            //Act
            var r = inputInstance.ReadLine(selection, true);

            //Assert
            Assert.That(r, Is.EqualTo(match.Key));
            Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + "Two " + match.Value));
        }
Пример #3
0
        public void Should_recall_command_in_several_layers_when_navigating_with_Tab()
        {
            //Arrange
            var input             = new[] { ConsoleKey.T, ConsoleKey.Tab, ConsoleKey.Spacebar, ConsoleKey.O, ConsoleKey.Tab, ConsoleKey.Spacebar, ConsoleKey.S, ConsoleKey.Tab, ConsoleKey.Enter };
            var consoleManager    = new FakeConsoleManager(new FakeKeyInputEngine(input));
            var console           = new TestConsole(consoleManager);
            var cancellationToken = new CancellationToken();
            var inputInstance     = new InputInstance(console, Constants.Prompt, null, cancellationToken);
            var match             = new CommandTreeNode <string>("SecondSub", "S");
            var selection         = new CommandTreeNode <string>(new[]
            {
                new CommandTreeNode <string>("First", "One"),
                new CommandTreeNode <string>("Second", "Two", new []
                {
                    new CommandTreeNode <string>("FirstA", "One", new []
                    {
                        new CommandTreeNode <string>("FirstSub", "ThirdOne"),
                        match,
                        new CommandTreeNode <string>("LastSub", "ThirdX"),
                    }),
                    new CommandTreeNode <string>("SecondSub", "SubTwo"),
                    new CommandTreeNode <string>("LastSub", "SubX"),
                }),
                new CommandTreeNode <string>("Last", "x")
            });

            //Act
            var r = inputInstance.ReadLine(selection, true);

            //Assert
            Assert.That(r, Is.EqualTo(match.Key));
            Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + "Two One " + match.Value));
        }
Пример #4
0
    public void Initialize(PlayerController playerController)
    {
        // Store references
        this.mainPlayerController = playerController;

        // Initialize input class
        this.InputInstance = new InputInstance();
    }
    // Update is called once per frame
    public void UpdateCamera(InputInstance inputInstance)
    {
        // Execute camera rotation
        this.ExecuteCameraVerticalRotation(inputInstance);

        // Execute camera collisions
        this.ExecuteCameraCollisions();

    }
Пример #6
0
 private void ExitInput()
 {
     PreviousInput = ActiveInput;
     if (ActiveInput.JewelsDraggedOver.Count > 0)
     {
         ActiveInput.UnlightDraggedOverJewels();
     }
     ActiveInput = null;
 }
Пример #7
0
    private static bool ShouldChangePlaces(InputInstance input)
    {
        if (input.JewelsDraggedOver.Count != 2)
        {
            return(false);
        }

        var neighbors  = input.JewelsDraggedOver[0].Neighbors;
        var isNeighbor = neighbors.Contains(input.JewelsDraggedOver[1]);

        return(isNeighbor);
    }
Пример #8
0
    public void DragUpdate(RaycastHit hit, InputInstance parentInstance)
    {
        if (hit.collider == null)
        {
            return;
        }

        if (!parentInstance.JewelsDraggedOver.Contains(hit.collider.gameObject.GetComponent <Jewel>()))
        {
            parentInstance.AddDraggedOver(hit.collider.GetComponent <Jewel>());
        }
    }
Пример #9
0
        public void GetObjectByInterface()
        {
            IInput o = new InputInstance();

            var agent = new TransientAgent();

            agent.Set(o);

            Transient <IInput> transient;
            var b = agent.TryGet(out transient);

            Assert.IsTrue(b);

            Assert.IsInstanceOfType(transient.Value, typeof(IInput));
        }
Пример #10
0
        public void Should_return_the_string_that_was_entered()
        {
            //Arrange
            var input          = new[] { ConsoleKey.A, ConsoleKey.B, ConsoleKey.C, ConsoleKey.Enter };
            var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input));
            var console        = new TestConsole(consoleManager);

            var cancellationToken = new CancellationToken();
            var inputInstance     = new InputInstance(console, Constants.Prompt, null, cancellationToken);

            //Act
            var r = inputInstance.ReadLine <string>(null, true);

            //Assert
            Assert.That(r, Is.EqualTo("ABC"));
        }
Пример #11
0
        public void Should_recall_nothing_when_pressing_Tab_and_no_commands_are_provided()
        {
            //Arrange
            var input          = new[] { ConsoleKey.Tab, ConsoleKey.Enter };
            var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input));
            var console        = new TestConsole(consoleManager);

            var cancellationToken = new CancellationToken();
            var inputInstance     = new InputInstance(console, Constants.Prompt, null, cancellationToken);

            //Act
            var r = inputInstance.ReadLine <string>(null, true);

            //Assert
            Assert.That(r, Is.EqualTo(string.Empty));
        }
Пример #12
0
        public void Should_recall_second_command_when_pressing_Tab_Twise()
        {
            //Arrange
            var input             = new[] { ConsoleKey.Tab, ConsoleKey.Tab, ConsoleKey.Enter };
            var consoleManager    = new FakeConsoleManager(new FakeKeyInputEngine(input));
            var console           = new TestConsole(consoleManager);
            var cancellationToken = new CancellationToken();
            var inputInstance     = new InputInstance(console, Constants.Prompt, null, cancellationToken);
            var selection         = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "1"), new CommandTreeNode <string>("Second", "2"), new CommandTreeNode <string>("Last", "x") });

            //Act
            var r = inputInstance.ReadLine(selection, true);

            //Assert
            Assert.That(r, Is.EqualTo(selection.Subs[1].Key));
            Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + selection.Subs[1].Value));
        }
Пример #13
0
        internal void RaiseButtonHandlers(StylusButtonData stylusOutput, StylusButtonData value)
        {
            //before 0 now bigger then 0
            if (stylusOutput.Pressure == 0 && value.Pressure > 0)
            {
                InputInstance.RaiseStylusButtonDown(value);
            }

            if (stylusOutput.Pressure > 0 && value.Pressure == 0)
            {
                InputInstance.RaiseStylusButtonUp(value);
            }

            if (value.Pressure != 0)
            {
                InputInstance.RaiseStylusButtonChanged(value);
            }
        }
Пример #14
0
        public void Should_recall_last_command_when_pressing_Shift_Tab()
        {
            //Arrange
            var input             = new[] { new ConsoleKeyInfo('\t', ConsoleKey.Tab, true, false, false), new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false) };
            var consoleManager    = new FakeConsoleManager(new FakeKeyInputEngine(input));
            var console           = new TestConsole(consoleManager);
            var cancellationToken = new CancellationToken();
            var inputInstance     = new InputInstance(console, Constants.Prompt, null, cancellationToken);
            var selection         = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "1"), new CommandTreeNode <string>("Second", "2"), new CommandTreeNode <string>("Last", "x") });

            //Act
            var r = inputInstance.ReadLine(selection, true);

            //Assert
            var match = selection.Subs.Last();

            Assert.That(r, Is.EqualTo(match.Key));
            Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + match.Value));
        }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Dive Kick
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    private void ExecuteDive(InputInstance inputInstance)
    {
        if (inputInstance.Dive && (this.lastDiveTime + this.DiveColdown) < Time.time)
        {
            this.lastDiveTime = Time.time;

            // Execute dive kick
            Vector3 diveVector = this.transform.forward*this.DiveForce;

            // Execute final jump
            this.rigidBody.velocity = diveVector;

            // Play animation
            this.mainPlayerController.PlayerAvatarController.PlayDiveAnimation();
        }
    }
Пример #16
0
 private void InitInput(InputInstance newInstance)
 {
 }
Пример #17
0
 public void SetActiveInput(Jewel jewel)
 {
     ActiveInput = new InputInstance(jewel);
 }
    private void ExecuteCameraVerticalRotation(InputInstance inputInstance)
    {
        // Get camera vertical rotation
        this.rotationY += inputInstance.VerticalLook*this.SensitivityY*Time.timeScale;
        this.rotationY = this.ClampAngle(this.rotationY, MinimumY, MaximumY);
        Quaternion yQuaternion = Quaternion.AngleAxis(this.rotationY, -Vector3.right);

        // Apply smoothed rotation on Y
        Quaternion localEulerRotation = Quaternion.Slerp(this.transform.localRotation,
            this.originalLocalRotation*yQuaternion,
            this.SmoothSpeed*Time.smoothDeltaTime*60/Time.timeScale);

        // Apply final camera rotation
        this.transform.localRotation = localEulerRotation;
    }
Пример #19
0
 public void SetInstance()
 {
     this.instance = this.target.Get() ? this.target.Get().GetComponent <InputInstance>() : null;
 }
 private void UpdateCurrentGravity(InputInstance inputInstance)
 {
     // Rotate player object
     this.transform.up = -this.TargetGravity.normalized;
 }
    // FixedUpdate is called once per frame
    public void FixedUpdateMovement(InputInstance inputInstance)
    {
        // End game check
        if (GamePresenter.Instance.CurrentMatchState != GamePresenter.State.Running || !this.mainPlayerController.IsAlive)
        {
            this.rigidBody.velocity = Vector3.zero;
            return;
        }

        // Before doing anything, apply current gravity vector
        this.UpdateCurrentGravity(inputInstance);

        // Update player horizontal rotation
        this.UpdatePlayerRotation(inputInstance);

        // Set initial parameters
        RaycastHit hit = new RaycastHit();

        //set the vertical bounds of the capsule used to detect player collisions
        Vector3 p1 = this.transform.position;//bottom of player capsule
        Vector3 p2 = p1 - this.TargetGravity.normalized * capsule.height / 2;//top of player capsule

        //track rigidbody velocity
        Vector3 velocity = this.rigidBody.velocity;

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //Player Input
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        float inputY = 0, inputX = 0;

        //track movement buttons and set input vars
        //Input.Axis is not used here to have have more control over button states and to avoid glitches 
        //such as pressing opposite movement buttons simultaneously causing player to move very slow in one direction
        this.ProcessInputDirection(inputInstance, ref inputY, ref inputX);

        //Smooth our movement states using Mathf.Lerp
        this.InputXSmoothed = Mathf.Lerp(this.InputXSmoothed, inputX, Time.deltaTime * 6.0f);
        this.InputYSmoothed = Mathf.Lerp(this.InputYSmoothed, inputY, Time.deltaTime * 6.0f);

        // Send input for movement animation
        this.mainPlayerController.PlayerAvatarController.UpdateMovementAnimation(this.InputXSmoothed,this.InputYSmoothed, inputInstance.Sprint,this.Crouched);

        // Send input for movement sfx
        this.mainPlayerController.PlayerAudioController.UpdateMovementInputSFX(inputX, inputY, inputInstance.Sprint);

        //This is the start of the large block that performs all movement actions while Grounded	
        if (this.Grounded)
        {
            // Process player while landing
            this.FallingPlayerCalculations();

            // Sets or disables crouch mode
            this.CrouchModeHandling(inputInstance, p1, p2,hit);

            // Execute player sprinting
            this.ExecutePlayerSprinting(inputInstance, inputY);

            // Process player movement speed
            this.CalculatePlayerMovementSpeed(inputY, inputX);

            // Execute player jumping
            this.ExecutePlayerJumping(inputInstance, velocity);

            // Execute dive kick
            this.ExecuteDive(inputInstance);
        }
        else
        {
            //Player is airborn////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //keep track of the time that player lost grounding for air manipulation and moving gun while Jumping
            if (this.airTimeState)
            {
                this.AirTime = Time.time;
                this.airTimeState = false;
            }
            // Execute Falling player calculations
            this.ExecuteFalling();
        }

        // Execute player calculations while crouching
        this.ExecuteCrouching(inputInstance);

        // Execute player ground check
        this.ApplyPlayerGroundCheck(p1, p2);
        
        // Set player final velocity
        this.SetPlayerVelocity(inputX, inputY, velocity);
    }
    private void ProcessInputDirection(InputInstance inputInstance, ref float inputY, ref float inputX)
    {
        Vector2 inputVector = new Vector2(inputInstance.StrafeRight, inputInstance.MoveForward);

        inputY = inputVector.normalized.y;
        inputX = inputVector.normalized.x;
    }
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //Crouching
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 private void ExecuteCrouching(InputInstance inputInstance)
 {
     if (Time.timeSinceLevelLoad > 0.5f)
     {
         //crouch
         if (this.Crouched)
         {
             if (this.MidPos > 0.45f)
             {
                 this.MidPos -= 5*Time.deltaTime;
             } //decrease camera height to crouch height
             if (this.capsule.height > 1.25f)
             {
                 this.capsule.height -= 5*Time.deltaTime;
             } //decrease capsule height to crouch height
         }
         else
         {
             if (this.MidPos < 0.9f)
             {
                 this.MidPos += 2.25f*Time.deltaTime;
             } //increase camera height to standing height
             if (this.capsule.height < 2.0f)
             {
                 this.capsule.height += 2.25f*Time.deltaTime;
             } //increase camera height to standing height
         }
     }
 }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Jumping
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    private void ExecutePlayerJumping(InputInstance inputInstance, Vector3 velocity)
    {
        if (this.Jumping)
        {
            //play landing sound effect after landing from jump and reset jumpfxstate
            if (this.jumpTimer + 0.25f < Time.time)
            {
                //play landing sound
                /*
				this.mainPlayerInput.AudioController.PlayLandSfx(
					this.mainPlayerInput.CameraController.MainCamera.transform.position);

                //play landing animation
				this.mainPlayerInput.CameraController.RequestPlayLandAnimation();
                */

                // set control variable
                this.jumpfxstate = true;
            }
            //reset Jumping var (this check must be before Jumping var is set to true below)
            this.Jumping = false;

            //allow a small amount of time for capsule to become un-grounded before setting
            //jump button state to false to prevent continuous Jumping if jump button is held.
            if (this.jumpTimer + 0.25f < Time.time)
            {
                this.jumpBtn = false;
            }
        }

        //determine if player is Jumping and set Jumping variable
        if (inputInstance.Jump
            && !this.Zoomed
            && this.jumpBtn //check that jump button is not being held
            && !this.Crouched
            && this.LandStartTime + this.AntiBunnyHopFactor < Time.time //check for bunnyhop delay before Jumping
            )
        {
            //do not jump if ground normal is greater than SlopeLimit
            if (!this.Jumping)
            {
                this.Jumping = true;
                //track the time we began to jump
                this.jumpTimer = Time.time;
            }

            //apply the jump velocity to the player rigidbody
            Vector3 jumpVector;

            // Execute regular jump
            if (!this.rayTooSteep)
                jumpVector = -this.TargetGravity.normalized * Mathf.Sqrt(2 * this.JumpSpeed * Mathf.Abs(this.TargetGravity.magnitude));
            // Execute slope jump
            else
                jumpVector = this.steepRayNormal.normalized * Mathf.Sqrt(2 * this.JumpSpeed * Mathf.Abs(this.TargetGravity.magnitude));

            // Before executig the jump, neutralize the velocity of the direction we are going to jump to
            velocity = velocity - new Vector3(velocity.x * Mathf.Abs(this.TargetGravity.normalized.x),
                                              velocity.y * Mathf.Abs(this.TargetGravity.normalized.y),
                                              velocity.z * Mathf.Abs(this.TargetGravity.normalized.z));

            // Execute final jump
            this.rigidBody.velocity = new Vector3(velocity.x, velocity.y, velocity.z) + jumpVector;


            // Play animation
            this.mainPlayerController.PlayerAvatarController.PlayJumpAnimation();
        }

        //set jumpBtn to false to prevent continuous Jumping while holding jump button.
        if (!inputInstance.Jump && this.LandStartTime + this.AntiBunnyHopFactor < Time.time)
        {
            this.jumpBtn = true;
        }
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Sprinting
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    private void ExecutePlayerSprinting(InputInstance inputInstance, float inputY)
    {
        // Hold sprint configuration
        this.SprintActive = inputInstance.Sprint;

        //determine if player can run 
        if (inputY != 0.0f
            && this.SprintActive
            && !this.Crouched
            && (!this.CancelSprint || (this.CancelSprint && this.Zoomed))
            && this.Grounded)
        {
            this.CanRun = true;
            this.Zoomed = false; //cancel zooming when sprinting
            this.sprintStopState = true;
        }
        else
        {
            if (this.sprintStopState)
            {
                this.SprintStopTime = Time.time;
                this.sprintStopState = false;
            }
            this.CanRun = false;
        }
    }
 private void UpdatePlayerRotation(InputInstance inputInstance)
 {
     this.rotationX += inputInstance.HorizontalLook * this.mainPlayerController.CameraController.SensitivityX * Time.timeScale;
     transform.eulerAngles = new Vector3(0.0f, this.rotationX, 0.0f);
 }
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //Crouch Mode Handling
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 private void CrouchModeHandling(InputInstance inputInstance, Vector3 p1, Vector3 p2, RaycastHit hit)
 {
     //set Crouched variable that other scripts will access to check for crouching
     if (inputInstance.Crouch)
     {
         if (!this.crouchState)
         {
             // Check that we aren't already crouched
             if (!this.Crouched)
             {
                 this.Crouched = true;
                 this.SprintActive = false; //cancel sprint if crouch button is pressed
             }
             else
             {
                 // To disable crouch, first check we don't have anything above us
                 if (!this.CheckForCollidersAbove(p1))
                     this.Crouched = false;
             }
             this.crouchState = true;
         }
     }
     else
     {
         this.crouchState = false;
         if ((this.SprintActive || this.Climbing) && !this.CheckForCollidersAbove(p1))
         {
             this.Crouched = false; //cancel crouch if sprint button is pressed
         }
     }
     //cancel crouch if jump button is pressed
     if (inputInstance.Jump && this.Crouched &&
         !this.CheckForCollidersAbove(p1))
     {
         this.Crouched = false;
     }
 }
Пример #28
0
 public void Select(InputInstance inputInstance)
 {
     LightOn();
 }