init
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using RPGCore.Movement.ObjectModules.UnitMovement;
|
||||
using RPGCore.Core;
|
||||
using RPGCore.Core.Objects;
|
||||
using RPGCore.Movement.ObjectModules.UnitMovement.Actions;
|
||||
using RPGCore.ObjectModules.ActionObjectModule;
|
||||
using RPGCoreCommon.Helpers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace RPGCore.Movement.SceneModules.ActionController
|
||||
{
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(ActionCameraModule))]
|
||||
public class ActionControllerModule : SceneModule
|
||||
{
|
||||
[SerializeField] private UnitObject _unit;
|
||||
[SerializeField] private InputActionReference _rotateInput;
|
||||
[SerializeField] private InputActionReference _moveInput;
|
||||
[SerializeField] private InputActionReference _moveFasterInput;
|
||||
[SerializeField] private InputActionReference _jumpInput;
|
||||
|
||||
private Camera _camera;
|
||||
private BaseActionParallel _moveAction;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var movementModule = _unit.GetComponent<UnitMovementModule>();
|
||||
|
||||
_rotateInput.action.performed += _ =>
|
||||
{
|
||||
movementModule.rotateYaw = _camera.transform.rotation.eulerAngles.y;
|
||||
};
|
||||
|
||||
_moveInput.action.performed += _ =>
|
||||
{
|
||||
_moveAction = new DirectionMoveAction(GetDirection);
|
||||
_unit.actions.Execute(_moveAction);
|
||||
};
|
||||
_moveInput.action.canceled += _ =>
|
||||
{
|
||||
_moveAction?.CancelIt();
|
||||
_moveAction = null;
|
||||
};
|
||||
|
||||
_moveFasterInput.action.performed += _ => movementModule.isSprinting = true;
|
||||
_moveFasterInput.action.canceled += _ => movementModule.isSprinting = false;
|
||||
|
||||
_jumpInput.action.performed += _ => _unit.actions.Execute(new JumpAction());
|
||||
|
||||
movementModule.rotateType = UnitMovementRotateType.CustomDirection;
|
||||
}
|
||||
|
||||
private Vector3 GetDirection()
|
||||
{
|
||||
var input = _moveInput.action.ReadValue<Vector2>();
|
||||
return _camera.transform.right.SetY(0).normalized * input.x
|
||||
+ _camera.transform.forward.SetY(0).normalized * input.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user