/// <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> protected 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> /// Method used when creating an UIComponent that needs to be under an UICanvas directly. /// It looks if the selected object has an UICanvas component (and returns it. /// If the selected object does not have an UICanvas component it searches for one at it's hierarchy root. /// If the selected object is null or no UICanvas was found, it returns the MasterCanvas GameObject to be used as a parent /// </summary> /// <param name="selectedObject"> Selected object </param> protected static GameObject GetCanvasAsParent(GameObject selectedObject) { if (selectedObject == null) { return(UICanvas.GetMasterCanvas().gameObject); //selected object is null -> returns the MasterCanvas GameObject } if (selectedObject.GetComponent <UICanvas>()) { return(selectedObject); //selected object has an UICanvas -> returns its GameObject } if (selectedObject.transform.root.GetComponent <UICanvas>()) { return(selectedObject.transform.root.gameObject); //selected object root has an UICanvas -> returns the root GameObject } return(UICanvas.GetMasterCanvas().gameObject); //selected object is NOT null, but has no UICanvas -> returns the MasterCanvas GameObject }