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; using Unity.Netcode;
namespace Reset.Units{ namespace Reset.Units{
public class UnitMovementHandler : UnitComponent{ public class UnitMovementHandler : UnitComponent {
[ShowInInspector, InlineProperty, HideLabel, FoldoutGroup("Resolved Movement", expanded: true)] [ShowInInspector, InlineProperty, HideLabel, FoldoutGroup("Resolved Movement", expanded: true)]
public ResolvedMovement resolvedMovement; public ResolvedMovement resolvedMovement;
@@ -20,7 +20,7 @@ namespace Reset.Units{
// References // References
private CharacterController controller; private CharacterController controller;
private PlayerControls controls; private PlayerControls controls;
private LockOnManager lockOnManager; private IUnitTargetProvider targetProvider;
// Movement Data // Movement Data
[ShowInInspector, PropertyOrder(2), FoldoutGroup("Movement Data", expanded: true), InlineProperty, HideLabel] public UnitMovementData data = new(); [ShowInInspector, PropertyOrder(2), FoldoutGroup("Movement Data", expanded: true), InlineProperty, HideLabel] public UnitMovementData data = new();
@@ -31,7 +31,7 @@ namespace Reset.Units{
void Awake(){ void Awake(){
controller = GetComponent<CharacterController>(); controller = GetComponent<CharacterController>();
controls = GetComponent<PlayerControls>(); controls = GetComponent<PlayerControls>();
lockOnManager = GetComponent<LockOnManager>(); targetProvider = GetComponent<IUnitTargetProvider>();
InitAllSettings(); InitAllSettings();
} }
@@ -143,7 +143,7 @@ namespace Reset.Units{
// Just look at target // Just look at target
case PlayerFacingDirection.TowardsTarget: case PlayerFacingDirection.TowardsTarget:
// Look directly at the target // 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"); 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.Value = PlayerFacingDirection.Static;
data.facingDirection.currentValue = PlayerFacingDirection.Static; data.facingDirection.currentValue = PlayerFacingDirection.Static;
@@ -152,7 +152,7 @@ namespace Reset.Units{
break; break;
} }
targetRotation = Quaternion.LookRotation(transform.position.DirectionTo(lockOnManager.mainTarget.gameObject.transform.position)); targetRotation = Quaternion.LookRotation(transform.position.DirectionTo(targetProvider.UnitTarget.transform.position));
break; break;
case PlayerFacingDirection.Momentum: case PlayerFacingDirection.Momentum:
// Look towards the current direction the agent is moving // 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 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!"); Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
} }
} }
} }