popup ui

ㅋㅋ·2022년 9월 1일

UI 프리팹과 해당 UI가 사용할 스크립트의 이름을 같도록 구현

	public T ShowPopupUI<T>(string name = null, Transform parent = null) where T : UI_Popup
	{
		if (string.IsNullOrEmpty(name))
			name = typeof(T).Name;

		GameObject prefab = Managers.Resource.Load<GameObject>($"Prefabs/UI/Popup/{name}");

		GameObject go = Managers.Resource.Instantiate($"UI/Popup/{name}");
        
        ...
    }

필요할 때 UI 매니저를 통하여 ShowPopupUI 함수를 호출

매니저는 type을 통하여 해당 이름을 추출 후 프리팹에서 불러오도록 하였다.


popup UI들은 초기화할 때 UI 매니저를 호출하여 매니저의 순서를 통해

UI들 간의 canvas의 순서를 정하게 된다.

public void SetCanvas(GameObject go, bool sort = true)
{
	Canvas canvas = Utils.GetOrAddComponent<Canvas>(go);
	canvas.renderMode = RenderMode.ScreenSpaceOverlay;
	canvas.overrideSorting = true;

	if (sort)
	{
		canvas.sortingOrder = _order;
		_order++;
	}
	
    ...
}

0개의 댓글