public GameObject Open <T>(string dialogID, T vo) { GameObject prefab = Array.Find(DialogPrefabs, p => p.DialogID == dialogID).DialogPrefab; if (prefab == null) { return(null); } GameObject dialog = Instantiate(prefab, this.gameObject.transform); OpenDialogEventArgs arg = new OpenDialogEventArgs(dialogID, dialog); if (arg.ViewComponent != null) { arg.ViewComponent.Manager = this; arg.ViewComponent.ID = dialogID; arg.ViewComponent.OnOpen(); (arg.ViewComponent as DialogView <T>)?.OnOpen(vo); } _dialogs.Add(arg); dialog.transform.SetParent(transform, false); gameObject.SetActive(true); OnOpenDialog?.Invoke(this, arg); Blocker?.transform.SetSiblingIndex(transform.childCount - 2); return(dialog); }
public bool Close(GameObject dialog) { if (dialog == null) { return(false); } OpenDialogEventArgs arg = _dialogs.FirstOrDefault(a => a.DialogObject == dialog); if (arg == null || !_dialogs.Remove(arg)) { return(false); } bool openDialogs = _dialogs.Count > 0; arg.ViewComponent?.OnClose(); (arg.ViewComponent as IDisposable)?.Dispose(); Destroy(dialog); gameObject.SetActive(openDialogs); dialog = null; if (openDialogs) { Blocker?.transform.SetSiblingIndex(_dialogs.Count - 1); } OnCloseDialog?.Invoke(this, new CloseDialogEventArgs(arg.DialogID)); return(true); }