From f78b5d33a9f1a55354b435cc11110f902ece42be Mon Sep 17 00:00:00 2001 From: NTG Date: Fri, 29 Aug 2025 19:03:11 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BA=90=EB=A6=AD=ED=84=B0=20carrier=20?= =?UTF-8?q?=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Character/Core/CharacterCarrier.cs | 78 +++++++++++++++++++ .../Character/Core/CharacterCarrier.cs.meta | 2 + 2 files changed, 80 insertions(+) create mode 100644 Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs create mode 100644 Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs.meta 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