init
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using RPGCore.Movement.ObjectModules.UnitMovement.Events;
|
||||
using RPGCore.ObjectModules.ActionObjectModule;
|
||||
using RPGCore.ObjectModules.EventObjectModule;
|
||||
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule;
|
||||
using RPGCoreCommon.Settings;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RPGCore.Movement.ObjectModules.UnitMovement.Actions
|
||||
{
|
||||
public class DirectionMoveAction : BaseActionParallel
|
||||
{
|
||||
private readonly Func<Vector3> _directionGetter;
|
||||
|
||||
private StatusDefinitionSO _runStatusDefinitionSO;
|
||||
private StatusModule _unitStatus;
|
||||
private UnitMovementModule _unitMovement;
|
||||
|
||||
public DirectionMoveAction(Func<Vector3> directionGetter)
|
||||
{
|
||||
_directionGetter = directionGetter;
|
||||
}
|
||||
|
||||
public override void CanDoIt()
|
||||
{
|
||||
Check(
|
||||
unit.GetComponent<StatusModule>().IsControllable(),
|
||||
UnitIsBusyMessage);
|
||||
}
|
||||
|
||||
protected override void OnDoIt()
|
||||
{
|
||||
_runStatusDefinitionSO = SettingsManager.Get<MovementSettings>().runStatusDefinitionSO;
|
||||
_unitStatus = unit.GetComponent<StatusModule>();
|
||||
_unitMovement = unit.GetComponent<UnitMovementModule>();
|
||||
|
||||
var moveStartEvent = new MoveStartEvent{ unit = unit };
|
||||
|
||||
unit.events.InvokeBefore(moveStartEvent);
|
||||
Check(!moveStartEvent.isPrevented, ActionWasPreventedMessage);
|
||||
unit.events.InvokeAfter(moveStartEvent);
|
||||
|
||||
unit.StartCoroutine(MoveCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator MoveCoroutine()
|
||||
{
|
||||
while (state == ActionState.Running)
|
||||
{
|
||||
_unitMovement.moveInput = _directionGetter();
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEndIt()
|
||||
{
|
||||
_unitMovement.moveInput = Vector2.zero;
|
||||
_unitStatus.Remove(_runStatusDefinitionSO);
|
||||
unit.events.Invoke(new MoveEndEvent{ unit = unit });
|
||||
}
|
||||
|
||||
protected override void OnCancelIt()
|
||||
{
|
||||
OnEndIt();
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1c38778027246d1afc2fa822bc9826b
|
||||
timeCreated: 1766851215
|
||||
@@ -0,0 +1,36 @@
|
||||
using RPGCore.Movement.ObjectModules.UnitMovement.Events;
|
||||
using RPGCore.ObjectModules.ActionObjectModule;
|
||||
using RPGCore.ObjectModules.EventObjectModule;
|
||||
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule;
|
||||
using RPGCoreCommon.Helpers;
|
||||
|
||||
namespace RPGCore.Movement.ObjectModules.UnitMovement.Actions
|
||||
{
|
||||
public class JumpAction : BaseActionParallel
|
||||
{
|
||||
public override void CanDoIt()
|
||||
{
|
||||
Check(
|
||||
unit.GetComponent<StatusModule>().IsControllable(),
|
||||
UnitIsBusyMessage);
|
||||
Check(
|
||||
unit.GetComponent<UnitMovementModule>().isOnGround,
|
||||
"Unit is not on ground.");
|
||||
}
|
||||
|
||||
protected override void OnDoIt()
|
||||
{
|
||||
unit.rigidbody.linearVelocity = unit.rigidbody.linearVelocity.SetY(unit.GetComponent<UnitMovementModule>().jumpPower);
|
||||
unit.events.Invoke(new JumpEvent { unit = unit });
|
||||
EndIt();
|
||||
}
|
||||
|
||||
protected override void OnEndIt()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCancelIt()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc5b6c0c9dbe400ba3fb4f085bd3cc28
|
||||
timeCreated: 1767009824
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using RPGCore.Movement.ObjectModules.UnitMovement.Events;
|
||||
using RPGCore.ObjectModules.ActionObjectModule;
|
||||
using RPGCore.ObjectModules.EventObjectModule;
|
||||
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace RPGCore.Movement.ObjectModules.UnitMovement.Actions
|
||||
{
|
||||
public class PointMoveAction : BaseActionParallel
|
||||
{
|
||||
private readonly Vector3 _destination;
|
||||
|
||||
private UnitMovementModule _unitMovement;
|
||||
|
||||
public PointMoveAction(Vector3 destination)
|
||||
{
|
||||
_destination = destination;
|
||||
}
|
||||
|
||||
public override void CanDoIt()
|
||||
{
|
||||
Check(
|
||||
unit.GetComponent<StatusModule>().IsControllable(),
|
||||
UnitIsBusyMessage);
|
||||
}
|
||||
|
||||
protected override void OnDoIt()
|
||||
{
|
||||
_unitMovement = unit.GetComponent<UnitMovementModule>();
|
||||
|
||||
var moveStartEvent = new MoveStartEvent{ unit = unit };
|
||||
|
||||
unit.events.InvokeBefore(moveStartEvent);
|
||||
Check(!moveStartEvent.isPrevented, ActionWasPreventedMessage);
|
||||
unit.events.InvokeAfter(moveStartEvent);
|
||||
|
||||
unit.StartCoroutine(MovePoint_Coroutine());
|
||||
}
|
||||
|
||||
private IEnumerator MovePoint_Coroutine()
|
||||
{
|
||||
var agent = unit.GetComponent<NavMeshAgent>();
|
||||
agent.SetDestination(_destination);
|
||||
|
||||
var lastPosition = agent.transform.position;
|
||||
|
||||
while (state == ActionState.Running)
|
||||
{
|
||||
var speed = agent.speed = _unitMovement.moveMaxSpeed;
|
||||
if (agent.remainingDistance <= speed * Time.fixedDeltaTime)
|
||||
{
|
||||
EndIt();
|
||||
yield break;
|
||||
};
|
||||
|
||||
yield return new WaitForFixedUpdate();
|
||||
// unit.GetModule<EventModule>().Invoke(new MoveEvent
|
||||
// {
|
||||
// unit = unit,
|
||||
// lastPosition = lastPosition,
|
||||
// currentPosition = unit.transform.position
|
||||
// });
|
||||
//
|
||||
// lastPosition = unit.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEndIt()
|
||||
{
|
||||
unit.GetComponent<NavMeshAgent>().isStopped = true;
|
||||
unit.GetComponent<NavMeshAgent>().enabled = false;
|
||||
unit.events.Invoke(new MoveEndEvent{ unit = unit });
|
||||
}
|
||||
|
||||
protected override void OnCancelIt()
|
||||
{
|
||||
OnEndIt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3f6bf1842e54f00a5a385f9e2e4ba89
|
||||
timeCreated: 1766851215
|
||||
@@ -0,0 +1,121 @@
|
||||
using System.Collections;
|
||||
using RPGCore.ObjectModules.ActionObjectModule;
|
||||
using RPGCore.StatusEffect.ObjectModules.StatusObjectModule;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RPGCore.Movement.ObjectModules.UnitMovement.Actions
|
||||
{
|
||||
public class RotateAction : BaseActionParallel
|
||||
{
|
||||
private Coroutine _rotateCoroutine;
|
||||
|
||||
private readonly bool _isEndless;
|
||||
private float _targetYaw;
|
||||
private readonly float _rotationSpeed;
|
||||
private readonly bool _isForced;
|
||||
|
||||
public RotateAction(float rotationSpeed = 0)
|
||||
{
|
||||
_isEndless = true;
|
||||
_rotationSpeed = rotationSpeed;
|
||||
}
|
||||
|
||||
public RotateAction(float targetYaw, float rotationSpeed = 0, bool isForced = false)
|
||||
{
|
||||
_targetYaw = targetYaw;
|
||||
_rotationSpeed = rotationSpeed;
|
||||
_isForced = isForced;
|
||||
}
|
||||
|
||||
public RotateAction(Vector3 lookAt, float rotationSpeed = 0, bool isForced = false)
|
||||
{
|
||||
_targetYaw = Quaternion.LookRotation(lookAt - unit.transform.position).eulerAngles.y;
|
||||
_rotationSpeed = rotationSpeed;
|
||||
_isForced = isForced;
|
||||
}
|
||||
|
||||
public void SetYaw(float targetYaw)
|
||||
{
|
||||
if (!_isEndless)
|
||||
{
|
||||
Debug.LogWarning($"Usage {nameof(SetYaw)} available only when rotating is endless.");
|
||||
return;
|
||||
}
|
||||
|
||||
_targetYaw = targetYaw;
|
||||
}
|
||||
|
||||
public override bool IsInRange() => true;
|
||||
|
||||
public override void CanDoIt()
|
||||
{
|
||||
Check(
|
||||
_isForced || unit.GetComponent<StatusModule>().IsControllable(),
|
||||
UnitIsBusyMessage);
|
||||
}
|
||||
|
||||
protected override void OnDoIt()
|
||||
{
|
||||
BeforePerform();
|
||||
|
||||
// Instant rotation
|
||||
if (_rotationSpeed <= 0)
|
||||
{
|
||||
Rotate(_targetYaw);
|
||||
|
||||
AfterPerform();
|
||||
EndIt();
|
||||
return;
|
||||
}
|
||||
|
||||
// Endless rotation
|
||||
if (_isEndless)
|
||||
{
|
||||
_rotateCoroutine = unit.StartCoroutine(RotationEndlessCoroutine());
|
||||
return;
|
||||
}
|
||||
|
||||
// Simple rotation to given yaw
|
||||
_rotateCoroutine = unit.StartCoroutine(RotationCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator RotationCoroutine()
|
||||
{
|
||||
while (Mathf.Approximately(unit.transform.rotation.eulerAngles.y, _targetYaw) == false)
|
||||
{
|
||||
var deltaYaw = Mathf.DeltaAngle(unit.rigidbody.rotation.eulerAngles.y, _targetYaw);
|
||||
var deltaYawClamped = Mathf.Sign(deltaYaw) * Mathf.Clamp(Mathf.Abs(deltaYaw), 0, Time.fixedDeltaTime * _rotationSpeed);
|
||||
Rotate(unit.rigidbody.rotation.eulerAngles.y + deltaYawClamped);
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
|
||||
AfterPerform();
|
||||
EndIt();
|
||||
}
|
||||
|
||||
private IEnumerator RotationEndlessCoroutine()
|
||||
{
|
||||
while (state is ActionState.Running)
|
||||
{
|
||||
var deltaYaw = Mathf.DeltaAngle(unit.rigidbody.rotation.eulerAngles.y, _targetYaw);
|
||||
var deltaYawClamped = Mathf.Sign(deltaYaw) * Mathf.Clamp(Mathf.Abs(deltaYaw), 0, Time.fixedDeltaTime * _rotationSpeed);
|
||||
Rotate(unit.rigidbody.rotation.eulerAngles.y + deltaYawClamped);
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void Rotate(float yaw)
|
||||
{
|
||||
var targetRotation = unit.transform.rotation.eulerAngles;
|
||||
targetRotation.y = yaw;
|
||||
unit.rigidbody.MoveRotation(Quaternion.Euler(targetRotation));
|
||||
}
|
||||
|
||||
protected override void OnEndIt() { }
|
||||
|
||||
protected override void OnCancelIt()
|
||||
{
|
||||
if (_rotateCoroutine != null) unit.StopCoroutine(_rotateCoroutine);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a1273895fb44296a471ede97605bd81
|
||||
timeCreated: 1764945728
|
||||
Reference in New Issue
Block a user