![유니티 UI 참석 인원 표시](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbCkXYL%2FbtsATZ6YCnh%2Fvf7y8iRJ9eNKg0AkEbLU4K%2Fimg.png)
유니티 UI 참석 인원 표시Unity/UI2023. 11. 27. 20:55
Table of Contents
📌 참석 인원 표시하기
- 현재 참석한 인원의 이름을 표시하는 커뮤니티창 구현
- 이름 교체시 커뮤니티에 등록된 이름도 같이 교체
📌 구현 결과
- 인원 표시 창을 나타내게 하는 버튼과 현재 인원을 표시하는 리스트 창을 만들어 둔다.
📄 UI_Scene_Main.cs
private void InitViewCommunity()
{
communityShowBtn.onClick.AddListener(ShowCommunity);
communityHideBtn.onClick.AddListener(HideCommunity);
Manager.Game.CommunityList = communityList; // 등록할 커뮤니티창 게임매니저에서 설정
}
private void ShowCommunity()
{
communityPanel.SetActive(true);
}
private void HideCommunity()
{
communityPanel.SetActive(false);
}
- 인원 표시 창은 단순히 오른쪽에서 창만 확인 하면 되서, 따로 컨트롤 제어 없이 SetActive 체크만 해 두었다
- Manager.Game에서 생성된 인원에 따라서 설정된 CommunityList를 불러와서 표시하게 만든다.
📄 Add Community List
private void Start()
{
var communityNameObj = Manager.Resource.Instantiate("UI_Community_Name", Manager.Game.CommunityList);
var communityName = communityNameObj.GetComponent<TextMeshProUGUI>();
communityName.text = displayName.text;
}
- 리소스 매니저를 통해 커뮤니티 리스트를 생성하여 해당 캐릭터에 이름을 대입한다.
- 지금은 Start에서 처리하지만 나중에 플레이어와 npc를 생성 관리할 때, 코드를 리팩토링 해야한다.
📄 Change Community Name
public void InitName()
{
displayName.text = PlayerPrefs.GetString("user_id", "defaultID");
// 커뮤니티 리스트 네임 변경
var communityName = communityNameObj.GetComponent<TextMeshProUGUI>();
communityName.text = displayName.text;
}
- Player 스크립트에서 이름 변경 부분에 따로 할당한 커뮤니티 오브젝트에 Text를 가져와 같이 변경하게 구현했다.
💡 결과 화면
'Unity > UI' 카테고리의 다른 글
유니티 UI 롱 버튼 구현 (0) | 2024.02.06 |
---|---|
유니티 로그라이크 미니맵 구현 (0) | 2023.12.20 |
유니티 UI 캐릭터 정보 변경 (0) | 2023.11.27 |
유니티 UI 캐릭터 선택 창 (0) | 2023.11.26 |
유니티 UI 현재 시간 표시 (0) | 2023.11.26 |