/// <summary> /// Sets the target direction when there is a movement commmand. /// </summary> /// <param name="_args"></param> protected virtual void OnActorCommandReceive(OnActorCommandReceiveEventArgs _args) { if (GetOwner == _args.baseArgs.actor) { if (_args.command.Equals(ActorCommands.Move)) { targetDirection = (Vector3)_args.value; } } }
/// <summary> /// Rotates the actor when the actor is aiming or auto aiming. /// </summary> /// <param name="_args"></param> private void OnActorCommandReceive(OnActorCommandReceiveEventArgs _args) { if (GetOwner == _args.baseArgs.actor) { if (_args.command.Equals(ActorCommands.Aim)) { RotateTowardsTargetDirection((Vector3)_args.value); } else if (_args.command.Equals(ActorCommands.AutoAim)) { Vector3 targetDirection = detectorComponent.GetTargetDirection; RotateTowardsTargetDirection(targetDirection); } } }
/// <summary> /// Called when the actor receibes a shoot command. /// </summary> /// <param name="_args"></param> private void OnShootCommand(OnActorCommandReceiveEventArgs _args) { if (GetOwner == _args.baseArgs.actor) { if (_args.command.Equals(ActorCommands.Shoot)) { float inputValue = (float)_args.value; // If the value is grater than 0.0f it means the button is pressed. if (inputValue > 0.0f) { PullTrigger(); } else { ReleaseTrigger(); } } } }
private void CatchMovementInput() { // Get the horizontal and vertical input. float horizontalInput = 0.0f; float verticalInput = 0.0f; if (forceMobileInput) { Vector2 virtualjoystickValue = movementJoystick.GetJoystickValue; horizontalInput = virtualjoystickValue.x; verticalInput = virtualjoystickValue.y; } else { horizontalInput = Input.GetAxis("Horizontal"); verticalInput = Input.GetAxis("Vertical"); } // Only send a movement command when there is movment input.. if (!horizontalInput.Equals(0.0f) || !verticalInput.Equals(0.0f)) { // Vertical input is mapped out to the z axis. Vector3 inputVector = new Vector3(horizontalInput, 0, verticalInput); OnActorCommandReceiveEventArgs args = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.Move, value = inputVector }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, args); } }
private void CatchAimInput() { Vector3 aimDirection; if (forceMobileInput) { if (aimJoystick.GetIsDragged) { aimDirection = new Vector3(aimJoystick.GetJoystickValue.x, 0, aimJoystick.GetJoystickValue.y); if (aimDirection.x != 0.0f || aimDirection.y != 0.0f) { OnActorCommandReceiveEventArgs aimArgs = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.Aim, value = aimDirection }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, aimArgs); // Also shoot when the player aims with the joystick. OnActorCommandReceiveEventArgs shootArgs = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.Shoot, // Means the shoot button is pressed. value = 1.0f }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, shootArgs); } } } else { Vector2 positionOnScreen = playerCamera.WorldToScreenPoint(GetOwner.transform.position); Vector2 mouseOnScreen = Input.mousePosition; aimDirection = mouseOnScreen - positionOnScreen; aimDirection.z = aimDirection.y; aimDirection.y = 0; if (aimDirection.x != 0.0f || aimDirection.y != 0.0f) { OnActorCommandReceiveEventArgs args = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.Aim, // Means the shoot button is pressed. value = aimDirection }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, args); } } }
private void CatchShootInput() { if (forceMobileInput) { if (aimJoystick.GetIsUp) { if (aimJoystick.GetIsTapped) { OnActorCommandReceiveEventArgs aimArgs = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.AutoAim }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, aimArgs); OnActorCommandReceiveEventArgs shootArgs = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.Shoot, // Means the shoot button is pressed. value = 1.0f }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, shootArgs); } else { OnActorCommandReceiveEventArgs args = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.Shoot, // Means the shoot button has been released. value = 0.0f }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, args); } } } else { if (Input.GetButtonDown("Fire1")) { OnActorCommandReceiveEventArgs args = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.Shoot, // Means the shoot button is pressed. value = 1.0f }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, args); } if (Input.GetButtonUp("Fire1")) { OnActorCommandReceiveEventArgs args = new OnActorCommandReceiveEventArgs() { baseArgs = new OnActorEventEventArgs() { actor = GetOwner }, command = ActorCommands.Shoot, // Means the shoot button has been released. value = 0.0f }; EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, args); } } }