UI NetWork, NetWork
UI의 역할
- 해당 페이지를 열어준다.
- 네트워크(기능 미구현) 페이지를 열어준다.
필요한 변수들 선언
using UnityEngine;
public class UI_5_NetWork : MonoBehaviour
{
private static UI_5_NetWork instance = null;
// UI Window
public GameObject UI_W_NetWork = null;
public static UI_5_NetWork Instance
{
get
{
if (instance == null)
{
instance = FindObjectOfType<UI_5_NetWork>();
if (instance == null)
{
GameObject singletonObject = new GameObject(typeof(UI_5_NetWork).Name);
instance = singletonObject.AddComponent<UI_5_NetWork>();
DontDestroyOnLoad(singletonObject);
}
}
return instance;
}
}
...
}
public class UI_7_Help : MonoBehaviour
{
private static UI_7_Help instance = null;
// UI Window
public GameObject UI_W_Help = null;
public static UI_7_Help Instance
{
get
{
if (instance == null)
{
instance = FindObjectOfType<UI_7_Help>();
if (instance == null)
{
GameObject singletonObject = new GameObject(typeof(UI_7_Help).Name);
instance = singletonObject.AddComponent<UI_7_Help>();
DontDestroyOnLoad(singletonObject);
}
}
return instance;
}
}
...
}
*Detail 부분에 HP는 다른 팀원이 구현했으므로 따로 설명하지는 않을 것이다.
- UI_0_HUD
- 싱글톤 패턴을 구현하기 위한 인스턴스
기본 함수(Awake, Start, Update)
using UnityEngine;
public class UI_5_NetWork : MonoBehaviour
{
....
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this.gameObject);
}
else if (instance != this)
{
Destroy(gameObject);
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
...
}
public class UI_7_Help : MonoBehaviour
{
...
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this.gameObject);
}
else if (instance != this)
{
Destroy(gameObject);
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
...
}
Awake()
싱글톤 인스턴스 설정과 씬 전환 시 객체를 유지하게 만들고, 현재 오브젝트가 기존 인스턴스와 다른 경우 파괴하도록 만들어줬다.
UI Active 관련 함수
using UnityEngine;
public class UI_5_NetWork : MonoBehaviour
{
...
public void OpenUI()
{
if (UI_W_NetWork != null)
{
UI_W_NetWork.SetActive(true);
}
}
public void CloseUI()
{
if (UI_W_NetWork != null)
{
UI_W_NetWork.SetActive(false);
}
}
}
public class UI_7_Help : MonoBehaviour
{
...
public void OpenUI()
{
if (UI_W_Help != null)
{
UI_W_Help.SetActive(true);
}
}
public void CloseUI()
{
if (UI_W_Help != null)
{
UI_W_Help.SetActive(false);
}
}
}
UI 매니저에서 각각의 UI 요소들의 Active 상태를 제어하는 OpenUI, CloseUI 함수를 정의해 유지보수성을 높였다.
상태 변화를 제어하는 것을 이 함수들을 사용하는 것으로 한정해 불필요한 활성화/비활성화로 부작용을 방지하도록 만들었다.
참고 사항
UI Manager
[Unity] UI Manager 구현
UI ManagerUI Manager 기본정보큰 UI의 틀이 있고 버튼을 통해 총 7개의 화면 전환이 있어야 한다.기본 정보를 보여주는 UI게임 기능인 프로그램의 정보를 띄워주는 UI인벤토리처럼 획득한 아이템 리스
gdoo.tistory.com
마무리하며..
이 UI들은 창을 띄우기만 기능하도록 만들었다.
네트워크는 아직 기능이 미구현되어 있고, 도움말 창은 단순히 창만 띄우면 끝이라 할 게 없었다.
추후 작업하는데 어려움이 없도록 모듈화만 해두었다.
'Unity > Hackers Window' 카테고리의 다른 글
[Unity] PInformation, Program Manager : 버프/디버프 (0) | 2024.11.26 |
---|---|
[Unity] UI 8 : ProgramInstall (0) | 2024.11.25 |
[Unity] UI 6 : Control(환경설정 UI) (1) | 2024.11.23 |
[Unity] UI 3 : MyDocument(Inventory UI) (0) | 2024.11.22 |
[Unity] UI 3 : DownLoad (0) | 2024.11.21 |