캐릭터 carrier 컴포넌트 추가
This commit is contained in:
parent
362444c1a5
commit
f78b5d33a9
@ -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<ISpeechBubble>();
|
||||||
|
_speechBubble?.Show(_currentCarriable.GetCarrierId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Use(ICarriable carriable)
|
||||||
|
{
|
||||||
|
_currentCarriable = null;
|
||||||
|
|
||||||
|
_speechBubble.Hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f92b168407b75f14aa1941f878c9a4d5
|
Loading…
Reference in New Issue
Block a user