/// <summary> /// Looks in the UIPopupManager PopupsDatabase for an UIPopup prefab linked to the given popup name. /// If found, it instantiates a clone of it and returns a reference to it. Otherwise it returns null /// </summary> /// <param name="popupName"> Popup name to search for </param> public static UIPopup GetPopup(string popupName) { if (PopupDatabase.IsEmpty) { DDebug.Log("No Popups have been defined in the Popups Database. Open the Control Panel at the Popups section and add some there."); return(null); } if (!PopupDatabase.Contains(popupName)) { DDebug.Log("No Popup with the name '" + popupName + "' has been defined in the Popups Database. Open the Control Panel at the Popups section and add it there."); return(null); } GameObject prefab = PopupDatabase.GetPrefab(popupName); if (prefab == null) { DDebug.Log("No Popup prefab with the '" + popupName + "' PopupName has been defined in the Popups Database. Open the Control Panel at the Popups section and add it there."); return(null); } UICanvas canvas = prefab.GetComponent <UIPopup>().GetTargetCanvas(); GameObject clone = Instantiate(prefab, canvas.transform); var popup = clone.GetComponent <UIPopup>(); popup.SetPopupName(popupName); return(popup); }
/// <summary> Returns the UICanvas named 'PopupCanvas' and sets its render mode to ScreenSpaceOverlay </summary> public static UICanvas GetPopupOverlayCanvas() { UICanvas canvas = UICanvas.GetUICanvas(DEFAULT_POPUP_CANVAS_NAME, true); canvas.Canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvas.Canvas.sortingOrder = DEFAULT_POPUP_CANVAS_OVERLAY_SORT_ORDER; return(canvas); }
/// <summary> /// Method used when creating an UIComponent. /// It looks if the selected object has a RectTransform (and returns it as the parent). /// If the selected object is null or does not have a RectTransform, it returns the MasterCanvas GameObject as the parent. /// </summary> /// <param name="selectedObject"> Selected object </param> private static GameObject GetParent(GameObject selectedObject) { if (selectedObject == null) { return(UICanvas.GetMasterCanvas().gameObject); //selected object is null -> returns the MasterCanvas GameObject } return(selectedObject.GetComponent <RectTransform>() != null ? selectedObject : UICanvas.GetMasterCanvas().gameObject); }
/// <summary> Returns either the UICanvas named 'PopupCanvas' (if PopupDisplayOn.PopupCanvas) or another UICanvas with the target canvas name </summary> /// <param name="popupDisplayOn"> Where should the UIPopup be shown </param> /// <param name="targetCanvasName"> Target canvas name (used if PopupDisplayOn.TargetCanvas) </param> public static UICanvas GetTargetCanvas(PopupDisplayOn popupDisplayOn, string targetCanvasName) { return(popupDisplayOn == PopupDisplayOn.PopupCanvas ? GetPopupOverlayCanvas() : UICanvas.GetUICanvas(targetCanvasName)); }