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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user