2026.06.24
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public class MemoryPiecePickup : MonoBehaviour
|
||||
{
|
||||
[Header("Reference")]
|
||||
@@ -8,12 +9,17 @@ public class MemoryPiecePickup : MonoBehaviour
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private int amount = 1;
|
||||
[SerializeField] private bool destroyAfterPickup = true;
|
||||
[SerializeField] private bool destroyAfterPickup = false;
|
||||
[Tooltip("Destroy After Pickup이 꺼져 있을 때, 획득 후 오브젝트를 비활성화합니다.")]
|
||||
[SerializeField] private bool disableAfterPickup = true;
|
||||
[SerializeField] private bool autoFindManager = true;
|
||||
[SerializeField] private string playerTag = "Player";
|
||||
[Tooltip("Player Tag가 비어 있을 때 아무 Collider나 획득을 허용합니다. 테스트용이 아니면 끄는 것을 추천합니다.")]
|
||||
[SerializeField] private bool allowPickupWhenPlayerTagEmpty = false;
|
||||
|
||||
[Header("Events")]
|
||||
public UnityEvent onPickedUp;
|
||||
public UnityEvent onPickedUp = new UnityEvent();
|
||||
public UnityEvent onPickupFailed = new UnityEvent();
|
||||
|
||||
private bool pickedUp;
|
||||
|
||||
@@ -24,21 +30,50 @@ private void Awake()
|
||||
}
|
||||
|
||||
public void PickUp()
|
||||
{
|
||||
TryPickUp();
|
||||
}
|
||||
|
||||
public bool TryPickUp()
|
||||
{
|
||||
if (pickedUp)
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (memoryProgressManager == null)
|
||||
{
|
||||
Debug.LogWarning("[MemoryPiecePickup] MemoryProgressManager가 연결되지 않았습니다.", this);
|
||||
onPickupFailed?.Invoke();
|
||||
return false;
|
||||
}
|
||||
|
||||
int addedAmount = memoryProgressManager.AddMemoryPiece(amount);
|
||||
|
||||
if (addedAmount <= 0)
|
||||
{
|
||||
onPickupFailed?.Invoke();
|
||||
return false;
|
||||
}
|
||||
|
||||
pickedUp = true;
|
||||
|
||||
if (memoryProgressManager != null)
|
||||
memoryProgressManager.AddMemoryPiece(amount);
|
||||
else
|
||||
Debug.LogWarning("[MemoryPiecePickup] MemoryProgressManager가 연결되지 않았습니다.");
|
||||
|
||||
onPickedUp?.Invoke();
|
||||
|
||||
if (destroyAfterPickup)
|
||||
Destroy(gameObject);
|
||||
else if (disableAfterPickup)
|
||||
gameObject.SetActive(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ResetPickup()
|
||||
{
|
||||
pickedUp = false;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void SetMemoryProgressManager(MemoryProgressManager manager)
|
||||
{
|
||||
memoryProgressManager = manager;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
@@ -46,7 +81,35 @@ private void OnTriggerEnter(Collider other)
|
||||
if (pickedUp)
|
||||
return;
|
||||
|
||||
if (other.CompareTag(playerTag))
|
||||
PickUp();
|
||||
if (IsPlayerCollider(other))
|
||||
TryPickUp();
|
||||
}
|
||||
|
||||
private bool IsPlayerCollider(Collider other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(playerTag))
|
||||
return allowPickupWhenPlayerTagEmpty;
|
||||
|
||||
return other.CompareTag(playerTag);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
{
|
||||
amount = Mathf.Max(1, amount);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(playerTag) && !allowPickupWhenPlayerTagEmpty)
|
||||
{
|
||||
Debug.LogWarning("MemoryPiecePickup: Player Tag가 비어 있고 Allow Pickup When Player Tag Empty가 꺼져 있습니다. 이 상태에서는 트리거 획득이 작동하지 않습니다.", this);
|
||||
}
|
||||
|
||||
if (destroyAfterPickup && disableAfterPickup)
|
||||
{
|
||||
Debug.LogWarning("MemoryPiecePickup: Destroy After Pickup이 켜져 있으면 Disable After Pickup은 의미가 없습니다.", this);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user