maint: renamed player folder to units to match namespaces. added unit class as well.

This commit is contained in:
Chris
2025-10-04 01:05:37 -04:00
parent a80d1d487e
commit af0aab450b
38 changed files with 22 additions and 6 deletions

View File

@@ -0,0 +1,49 @@
using Reset.Items;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Reset.Units{
public class InteractionHandler : MonoBehaviour{
private PlayerEnvironmentManager envManager;
private Inventory inventory;
private EnvironmentObserver observer;
void Awake(){
envManager = GetComponent<PlayerEnvironmentManager>();
inventory = GetComponent<Inventory>();
observer = envManager.FindObserverFromString("itemdrop");
observer.active = true;
}
public void InteractWith(GameObject target){
IInteractable interactable = target.GetComponent<IInteractable>();
if (interactable == null) {
Debug.LogError("This item cannot be interacted with, it has no Interactable interface");
return;
}
if (target.GetComponent<ItemDrop>()) {
inventory.AddToInventory(target.GetComponent<ItemDrop>().item);
}
interactable.Interact();
// Don't do any actions that use the same button (hard set to Jump for now)
Debug.Log($"Just collected the item, consuming the input @ {Time.time}.");
GetComponent<PlayerControls>().SendInputBlock("Jump");
}
void OnInteract(){
CheckForInteraction();
}
private void CheckForInteraction(){
if (observer.active && observer.Evaluate(gameObject)) {
InteractWith(observer.hit.transform.gameObject);
}
}
}
}