diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs new file mode 100644 index 000000000..81abaa03d --- /dev/null +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs @@ -0,0 +1,78 @@ +using UnityEngine; + +namespace DDD +{ + public enum CarriableType + { + None = 0, + GameObjectItem, // 실제 GameObject + VirtualItem // ID만 존재하는 가상 아이템 + } + + public interface ICarrier + { + GameObject GetCarrierGameObject(); + string GetCarrierId(); + ICarriable GetCurrentCarriable(); + bool CanCarryTo(ICarriable carriable); + void Carry(ICarriable carriable); + void Use(ICarriable carriable); + } + + public interface ICarriable + { + string GetCarrierId(); + CarriableType GetCarriableType(); + void OnCarried(ICarrier carrier); + bool CanCarry(); + + // 실제 오브젝트인 경우에만 유효 + GameObject GetGameObject(); + } + + public class CharacterCarrier : MonoBehaviour, ICarrier + { + private ICarriable _currentCarriable; + private ISpeechBubble _speechBubble; + + public GameObject GetCarrierGameObject() + { + return gameObject; + } + + public string GetCarrierId() + { + return _currentCarriable.GetCarrierId(); + } + + public ICarriable GetCurrentCarriable() + { + return _currentCarriable; + } + + public bool CanCarryTo(ICarriable carriable) + { + if (_currentCarriable != null) return false; + if (carriable == null) return false; + if (carriable.CanCarry() == false) return false; + + return true; + } + + public void Carry(ICarriable carriable) + { + _currentCarriable = carriable; + _currentCarriable.OnCarried(this); + + _speechBubble ??= GetComponentInChildren(); + _speechBubble?.Show(_currentCarriable.GetCarrierId()); + } + + public void Use(ICarriable carriable) + { + _currentCarriable = null; + + _speechBubble.Hide(); + } + } +} \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs.meta b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs.meta new file mode 100644 index 000000000..4b71b417c --- /dev/null +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f92b168407b75f14aa1941f878c9a4d5 \ No newline at end of file