스스로 불러온 재앙에 짓눌려~ 2
public interface INpc
{
public string Name { get; }
public string Dialog { get; }
void InteractWithPlayer();
}
public class Npc : MonoBehaviour, INpc
{
public string Name { get; }
public string Dialog { get; }
private GameObject canvas;
public Npc(string name, string dialog)
{
Name = name;
Dialog = dialog;
}
public void InteractWithPlayer()
{
UIManager.U.SetNpcDialogPanel(Name, Dialog);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
canvas = GameObject.FindWithTag("Canvas");
if (canvas == null) return;
InteractWithPlayer();
canvas.transform.Find("CallNpcPanel").gameObject.SetActive(true);
}
}
private void OnTriggerExit2D(Collider2D collision)
{
canvas = GameObject.FindWithTag("Canvas");
if (canvas == null) return;
canvas.transform.Find("CallNpcPanel").gameObject.SetActive(false);
canvas.transform.Find("NpcInteractionPanel").gameObject.SetActive(false);
}
}
public class JongminManagerNpc : Npc
{
static string name = "박종민 매니저";
static string dialog = "안녕하세요! 무슨 일로 찾아오셨나요?";
public JongminManagerNpc() : base(name, dialog) { }
}
private void LoadAttendeeList()
{
GameObject npcController = GameObject.Find("NpcController");
GameObject[] npcList = Resources.LoadAll<GameObject>("Prefabs/Npc");
foreach (GameObject npc in npcList)
{
GameObject curNpc = Instantiate(npc);
curNpc.transform.SetParent(npcController.transform);
}
UIManager.U.SetAttendeeList();
}
public void SetAttendeeList()
{
// 최상단에 플레이어 닉네임
GameObject playerName = Instantiate(Resources.Load<GameObject>("Prefabs/AttendeeName"));
playerName.GetComponent<Text>().text = PlayerPrefs.GetString(Player.PLAYER_NAME);
playerName.transform.SetParent(contentContainer);
// Npc 닉네임
GameObject npcController = GameObject.Find("NpcController");
int npcNum = npcController.transform.childCount;
for (int i = 0; i < npcNum; i++)
{
GameObject npcName = Instantiate(Resources.Load<GameObject>("Prefabs/AttendeeName"));
npcName.GetComponent<Text>().text = npcController.transform.GetChild(i).GetComponent<Npc>().Name;
npcName.transform.SetParent(contentContainer);
}
}
이렇게 해주면 스크롤 뷰의 Viewport - Content 하위에 이름 Text 오브젝트가 생성된다.
그리고 요렇게 이름이 짜잔
와~ 야근이다~
끗 ..