Interactable items - slotting working correctly and calling the dispatchers each time
This commit is contained in:
@@ -50,7 +50,7 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7447346505753002421, guid: bf4b9d7045397f946b2125b1ad4a3fbd, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: BasePuzzlePickup
|
||||
value: BurgerBuns
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
|
||||
@@ -14,7 +14,8 @@ public class DebugUIMessage : MonoBehaviour
|
||||
/// </summary>
|
||||
/// <param name="message">The message to display.</param>
|
||||
/// <param name="duration">How long to display the message (seconds).</param>
|
||||
public static void Show(string message, float duration = 2f)
|
||||
/// <param name="displayColor"></param>
|
||||
public static void Show(string message, Color displayColor, float duration = 2f)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
@@ -23,7 +24,7 @@ public class DebugUIMessage : MonoBehaviour
|
||||
instance.SetupUI();
|
||||
DontDestroyOnLoad(go);
|
||||
}
|
||||
instance.ShowMessage(message, duration);
|
||||
instance.ShowMessage(message, duration, displayColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,7 +46,7 @@ public class DebugUIMessage : MonoBehaviour
|
||||
messageText.font = customFont;
|
||||
else
|
||||
messageText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
|
||||
messageText.fontSize = 16;
|
||||
messageText.fontSize = 32;
|
||||
messageText.color = Color.yellow;
|
||||
var outline = textGO.AddComponent<Outline>();
|
||||
outline.effectColor = Color.black;
|
||||
@@ -55,16 +56,17 @@ public class DebugUIMessage : MonoBehaviour
|
||||
rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rect.pivot = new Vector2(0.5f, 0.5f);
|
||||
rect.anchoredPosition = Vector2.zero;
|
||||
rect.sizeDelta = new Vector2(400, 40);
|
||||
rect.sizeDelta = new Vector2(800, 40);
|
||||
messageText.text = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method to show a message and start the hide coroutine.
|
||||
/// </summary>
|
||||
private void ShowMessage(string message, float duration)
|
||||
private void ShowMessage(string message, float duration, Color fontColor)
|
||||
{
|
||||
messageText.text = message;
|
||||
messageText.color = fontColor;
|
||||
messageText.enabled = true;
|
||||
if (hideCoroutine != null)
|
||||
StopCoroutine(hideCoroutine);
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Interactions
|
||||
var step = GetComponent<PuzzleS.ObjectiveStepBehaviour>();
|
||||
if (step != null && !step.IsStepUnlocked())
|
||||
{
|
||||
DebugUIMessage.Show("This step is locked!", 2f);
|
||||
DebugUIMessage.Show("This step is locked!", Color.yellow);
|
||||
BroadcastInteractionComplete(false);
|
||||
// Reset variables for next time
|
||||
_interactionInProgress = false;
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace Interactions
|
||||
private PickupItemData _currentlySlottedItemData;
|
||||
public SpriteRenderer slottedItemRenderer;
|
||||
private GameObject _currentlySlottedItemObject = null;
|
||||
|
||||
|
||||
public GameObject GetSlottedObject()
|
||||
{
|
||||
@@ -38,107 +37,41 @@ namespace Interactions
|
||||
{
|
||||
var heldItemData = FollowerController.CurrentlyHeldItemData;
|
||||
var heldItemObj = FollowerController.GetHeldPickupObject();
|
||||
var pickup = GetComponent<Pickup>();
|
||||
var slotItem = pickup != null ? pickup.itemData : null;
|
||||
var config = GameManager.Instance.GetSlotItemConfig(slotItem);
|
||||
var allowed = config?.allowedItems ?? new List<PickupItemData>();
|
||||
var config = GameManager.Instance.GetSlotItemConfig(itemData);
|
||||
var forbidden = config?.forbiddenItems ?? new List<PickupItemData>();
|
||||
|
||||
if (heldItemData != null && _currentlySlottedItemObject != null)
|
||||
{
|
||||
// Remove the currently slotted item
|
||||
FollowerController.TryPickupItem(_currentlySlottedItemObject, _currentlySlottedItemData);
|
||||
_currentlySlottedItemObject = null;
|
||||
_currentlySlottedItemData = null;
|
||||
onItemSlotRemoved?.Invoke();
|
||||
UpdateSlottedSprite();
|
||||
|
||||
// Now slot the held item and check correctness
|
||||
if (forbidden.Contains(heldItemData))
|
||||
{
|
||||
DebugUIMessage.Show("Can't place that here.");
|
||||
onForbiddenItemSlotted?.Invoke();
|
||||
Interactable.BroadcastInteractionComplete(false);
|
||||
return;
|
||||
}
|
||||
|
||||
SlotItem(heldItemObj, heldItemData);
|
||||
if (allowed.Contains(heldItemData))
|
||||
{
|
||||
onCorrectItemSlotted?.Invoke();
|
||||
Interactable.BroadcastInteractionComplete(true);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUIMessage.Show("I'm not sure this works.");
|
||||
onIncorrectItemSlotted?.Invoke();
|
||||
Interactable.BroadcastInteractionComplete(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (heldItemData == null && _currentlySlottedItemObject != null)
|
||||
{
|
||||
FollowerController.TryPickupItem(_currentlySlottedItemObject, _currentlySlottedItemData);
|
||||
_currentlySlottedItemObject = null;
|
||||
_currentlySlottedItemData = null;
|
||||
onItemSlotRemoved?.Invoke();
|
||||
UpdateSlottedSprite();
|
||||
return;
|
||||
}
|
||||
|
||||
// // CASE 1: No held item, slot has item -> pick up slotted item
|
||||
// if (heldItemData == null && _cachedSlottedObject != null)
|
||||
// {
|
||||
// InteractionOrchestrator.Instance.PickupItem(FollowerController, _cachedSlottedObject);
|
||||
// _cachedSlottedObject = null;
|
||||
// currentlySlottedItem = null;
|
||||
// UpdateSlottedSprite();
|
||||
// Interactable.BroadcastInteractionComplete(false);
|
||||
// return;
|
||||
// }
|
||||
// // CASE 2: Held item, slot has item -> swap
|
||||
// if
|
||||
// {
|
||||
// InteractionOrchestrator.Instance.SwapItems(FollowerController, this);
|
||||
// currentlySlottedItem = heldItemData;
|
||||
// UpdateSlottedSprite();
|
||||
// return;
|
||||
// }
|
||||
// CASE 3: Held item, slot empty -> slot the held item
|
||||
// Held item, slot empty -> try to slot item
|
||||
if (heldItemData != null && _currentlySlottedItemObject == null)
|
||||
{
|
||||
// First check for forbidden items at the very start so we don't continue unnecessarily
|
||||
if (forbidden.Contains(heldItemData))
|
||||
{
|
||||
DebugUIMessage.Show("Can't place that here.");
|
||||
DebugUIMessage.Show("Can't place that here.", Color.red);
|
||||
onForbiddenItemSlotted?.Invoke();
|
||||
Interactable.BroadcastInteractionComplete(false);
|
||||
return;
|
||||
}
|
||||
|
||||
SlotItem(heldItemObj, heldItemData);
|
||||
if (allowed.Contains(heldItemData))
|
||||
{
|
||||
onCorrectItemSlotted?.Invoke();
|
||||
Interactable.BroadcastInteractionComplete(true);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUIMessage.Show("I'm not sure this works.");
|
||||
onIncorrectItemSlotted?.Invoke();
|
||||
Interactable.BroadcastInteractionComplete(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// CASE 4: No held item, slot empty -> show warning
|
||||
if (heldItemData == null && _currentlySlottedItemObject == null)
|
||||
{
|
||||
DebugUIMessage.Show("This requires an item.");
|
||||
SlotItem(heldItemObj, heldItemData, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Either pickup or swap items
|
||||
if ((heldItemData == null && _currentlySlottedItemObject != null)
|
||||
|| (heldItemData != null && _currentlySlottedItemObject != null))
|
||||
{
|
||||
FollowerController.TryPickupItem(_currentlySlottedItemObject, _currentlySlottedItemData, false);
|
||||
onItemSlotRemoved?.Invoke();
|
||||
SlotItem(heldItemObj, heldItemData, _currentlySlottedItemObject == null);
|
||||
return;
|
||||
}
|
||||
|
||||
// No held item, slot empty -> show warning
|
||||
if (heldItemData == null && _currentlySlottedItemObject == null)
|
||||
{
|
||||
DebugUIMessage.Show("This requires an item.", Color.red);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -170,18 +103,43 @@ namespace Interactions
|
||||
}
|
||||
}
|
||||
|
||||
public void SlotItem(GameObject itemToSlot, PickupItemData itemToSlotData)
|
||||
public void SlotItem(GameObject itemToSlot, PickupItemData itemToSlotData, bool clearFollowerHeldItem = true)
|
||||
{
|
||||
if (itemToSlot == null)
|
||||
return;
|
||||
if (itemToSlot == null)
|
||||
{
|
||||
_currentlySlottedItemData = null;
|
||||
_currentlySlottedItemData = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemToSlot.SetActive(false);
|
||||
itemToSlot.transform.SetParent(null);
|
||||
SetSlottedObject(itemToSlot);
|
||||
|
||||
itemToSlot.SetActive(false);
|
||||
itemToSlot.transform.SetParent(null);
|
||||
SetSlottedObject(itemToSlot);
|
||||
|
||||
_currentlySlottedItemData = itemToSlotData;
|
||||
_currentlySlottedItemData = itemToSlotData;
|
||||
if (clearFollowerHeldItem)
|
||||
{
|
||||
FollowerController.ClearHeldItem();
|
||||
}
|
||||
}
|
||||
UpdateSlottedSprite();
|
||||
FollowerController.ClearHeldItem();
|
||||
|
||||
// Once an item is slotted, we know it is not forbidden, so we can skip that check, but now check if it was
|
||||
// the correct item we're looking for
|
||||
var config = GameManager.Instance.GetSlotItemConfig(itemData);
|
||||
var allowed = config?.allowedItems ?? new List<PickupItemData>();
|
||||
if (allowed.Contains(itemToSlotData))
|
||||
{
|
||||
DebugUIMessage.Show("You correctly slotted " + itemToSlotData.itemName + " into: " + itemData.itemName, Color.green);
|
||||
onCorrectItemSlotted?.Invoke();
|
||||
Interactable.BroadcastInteractionComplete(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUIMessage.Show("I'm not sure this works.", Color.yellow);
|
||||
onIncorrectItemSlotted?.Invoke();
|
||||
Interactable.BroadcastInteractionComplete(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,9 +311,9 @@ public class FollowerController: MonoBehaviour
|
||||
#endregion Movement
|
||||
|
||||
#region ItemInteractions
|
||||
public void TryPickupItem(GameObject itemObject, PickupItemData itemData)
|
||||
public void TryPickupItem(GameObject itemObject, PickupItemData itemData, bool dropItem = true)
|
||||
{
|
||||
if (_currentlyHeldItemData != null && _cachedPickupObject != null)
|
||||
if (_currentlyHeldItemData != null && _cachedPickupObject != null && dropItem)
|
||||
{
|
||||
// Drop the currently held item at the current position
|
||||
DropHeldItemAt(transform.position);
|
||||
|
||||
Reference in New Issue
Block a user