public T Generate <T>() where T : BaseUI { var origin = _resourceLoader?.Invoke(UI, $"{typeof(T).Name}.prefab"); if (origin == null) { Debug.LogError($"{nameof(T)}을(를) 불러오지 못했습니다! - origin이 NULL입니다!"); return(null); } var uiObject = GameObject.Instantiate <GameObject>(origin, _uiRoot); if (uiObject == null) { Debug.LogError($"{nameof(T)}을(를) 불러오지 못했습니다! - Prefab 생성에 실패했습니다."); return(null); } var ui = uiObject.AddComponent <T>(); ui.RegistPreCloseAction(RemoveFromStack); //__uiStackList.Push(ui); _uiStackList.Add(new UIPack(ui.id, ui)); if (_canvas.worldCamera == null) { _canvas.worldCamera = Camera.main; } return(ui); }
/// <summary> /// 일반적 형태의 UI Close 함수. 인자를 포함하지 않으면 Stack의 최상단부터 닫는다. /// </summary> /// <param name="index">기본값은 -1. 이외의 값이 들어간다면 Stack에서 해당 Index의 UIPack을 찾아서 닫는다.</param> public void Close(int index = -1) { if (_uiStackList.Count == 0) { Debug.LogError("Stack is EMPTY!"); return; } BaseUI ui = null; if (index < -1 || _uiStackList.Count <= index) { Debug.LogError($"INVALID index!: {index}"); return; } if (index == -1) { ui = _uiStackList.PopLast()?.ui; } else { ui = _uiStackList.Pop(index)?.ui; } ui?.CloseAction(); }
public void CloseWithID(int id) { if (_uiStackList.Count == 0) { Debug.LogError("Stack is EMPTY!"); return; } var uiPack = _uiStackList.Find(x => x.id == id); if (ReferenceEquals(uiPack, null)) { Debug.LogError("Cannot find UIPack!"); return; } uiPack.ui.CloseAction(); }
private void RemoveFromStack(BaseUI ui) { if (_uiStackList.Count == 0) { Debug.LogError("Stack is EMPTY!"); return; } var findUIPack = _uiStackList.Find(x => ReferenceEquals(x.ui, ui)); if (ReferenceEquals(findUIPack, null) == true) { Debug.LogError("ui is NOT IN Stack!"); return; } _uiStackList.Remove(findUIPack); }