improv: UnitMovementHandler.cs now uses IUnitTargetProvider

This commit is contained in:
Chris
2025-10-23 21:48:36 -04:00
parent 129a5226c5
commit f4714db41b

View File

@@ -5,7 +5,7 @@ using Sirenix.OdinInspector;
using Unity.Netcode;
namespace Reset.Units{
public class UnitMovementHandler : UnitComponent{
public class UnitMovementHandler : UnitComponent {
[ShowInInspector, InlineProperty, HideLabel, FoldoutGroup("Resolved Movement", expanded: true)]
public ResolvedMovement resolvedMovement;
@@ -20,7 +20,7 @@ namespace Reset.Units{
// References
private CharacterController controller;
private PlayerControls controls;
private LockOnManager lockOnManager;
private IUnitTargetProvider targetProvider;
// Movement Data
[ShowInInspector, PropertyOrder(2), FoldoutGroup("Movement Data", expanded: true), InlineProperty, HideLabel] public UnitMovementData data = new();
@@ -31,7 +31,7 @@ namespace Reset.Units{
void Awake(){
controller = GetComponent<CharacterController>();
controls = GetComponent<PlayerControls>();
lockOnManager = GetComponent<LockOnManager>();
targetProvider = GetComponent<IUnitTargetProvider>();
InitAllSettings();
}
@@ -143,7 +143,7 @@ namespace Reset.Units{
// Just look at target
case PlayerFacingDirection.TowardsTarget:
// Look directly at the target
if (lockOnManager.mainTarget == null) {
if (targetProvider.UnitTarget == null) {
Debug.LogError("Trying to rotate towards a target but there is no target. Forcing rotation to Static and continuing");
data.facingDirection.Value = PlayerFacingDirection.Static;
data.facingDirection.currentValue = PlayerFacingDirection.Static;
@@ -152,7 +152,7 @@ namespace Reset.Units{
break;
}
targetRotation = Quaternion.LookRotation(transform.position.DirectionTo(lockOnManager.mainTarget.gameObject.transform.position));
targetRotation = Quaternion.LookRotation(transform.position.DirectionTo(targetProvider.UnitTarget.transform.position));
break;
case PlayerFacingDirection.Momentum:
// Look towards the current direction the agent is moving
@@ -391,6 +391,7 @@ namespace Reset.Units{
public void OverwriteDirectionFromInput(Vector2 value, float priority, float speed = Mathf.Infinity){ // Old
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
}
}