Interactables fully working now

This commit is contained in:
Michal Pikulski
2025-09-10 17:38:03 +02:00
parent 4c8ffbfaf8
commit 487a0fa6d4
8 changed files with 101 additions and 109 deletions

View File

@@ -21,8 +21,12 @@ public class SlotItemBehavior : InteractionRequirementBase
private GameObject _cachedSlottedObject = null;
// Helper for slotting an object, with option to skip destruction (for swap)
private void SetSlottedObject(GameObject obj)
public GameObject GetSlottedObject()
{
return _cachedSlottedObject;
}
public void SetSlottedObject(GameObject obj)
{
_cachedSlottedObject = obj;
if (_cachedSlottedObject != null)
@@ -31,32 +35,6 @@ public class SlotItemBehavior : InteractionRequirementBase
}
}
private void RemoveSlottedObject()
{
if (_cachedSlottedObject != null)
{
Destroy(_cachedSlottedObject);
_cachedSlottedObject = null;
}
}
private void CacheSlottedObject(GameObject obj)
{
// Only destroy if not swapping
RemoveSlottedObject();
SetSlottedObject(obj);
}
private void RestoreSlottedObject()
{
if (_cachedSlottedObject != null)
{
_cachedSlottedObject.transform.SetParent(null);
// Do NOT activate or move the object here; it stays hidden until dropped
// Activation is handled by the drop logic elsewhere
}
}
/// <summary>
/// Attempts to interact with the slot, handling slotting, swapping, or picking up items.
/// </summary>
@@ -75,9 +53,7 @@ public class SlotItemBehavior : InteractionRequirementBase
// CASE 1: No held item, slot has item -> pick up slotted item
if (heldItem == null && _cachedSlottedObject != null)
{
// Give the hidden slotted object to the follower (do NOT activate or move it)
RestoreSlottedObject();
follower.SetHeldItemFromObject(_cachedSlottedObject);
InteractionOrchestrator.Instance.PickupItem(follower, _cachedSlottedObject);
_cachedSlottedObject = null;
currentlySlottedItem = null;
UpdateSlottedSprite();
@@ -86,20 +62,9 @@ public class SlotItemBehavior : InteractionRequirementBase
// CASE 2: Held item, slot has item -> swap
if (heldItem != null && _cachedSlottedObject != null)
{
var followerHeldObj = heldObj;
var followerHeldItem = heldItem;
var slotObj = _cachedSlottedObject;
var slotItemData = currentlySlottedItem;
// 1. Slot the follower's held object (do NOT destroy the old one)
SetSlottedObject(followerHeldObj);
currentlySlottedItem = followerHeldItem;
InteractionOrchestrator.Instance.SwapItems(follower, this);
currentlySlottedItem = heldItem;
UpdateSlottedSprite();
// 2. Give the slot's object to the follower (do NOT activate or move it)
RestoreSlottedObject();
follower.SetHeldItemFromObject(slotObj);
return true;
}
// CASE 3: Held item, slot empty -> slot the held item
@@ -110,7 +75,7 @@ public class SlotItemBehavior : InteractionRequirementBase
DebugUIMessage.Show("Can't place that here.");
return false;
}
CacheSlottedObject(heldObj);
InteractionOrchestrator.Instance.SlotItem(this, heldObj);
currentlySlottedItem = heldItem;
UpdateSlottedSprite();
follower.ClearHeldItem();