public static T GetComponent <T>([Optional, DefaultParameterValue(0)] IfNotExist ifNotExist) where T : MonoBehaviour { GameObject facebookGameObject = FacebookGameObject; T component = facebookGameObject.GetComponent <T>(); if ((component == null) && (ifNotExist == IfNotExist.AddNew)) { component = facebookGameObject.AddComponent <T>(); } return(component); }
/** * Gets one and only one component. Lazy creates one if it doesn't exist */ public static T GetComponent <T>(IfNotExist ifNotExist = IfNotExist.AddNew) where T : MonoBehaviour { var facebookGameObject = FacebookGameObject; T component = facebookGameObject.GetComponent <T>(); if (component == null && ifNotExist == IfNotExist.AddNew) { component = facebookGameObject.AddComponent <T>(); } return(component); }
public static T GetChildComponent <T>(GameObject parent, IfNotExist ifNotExist = IfNotExist.AddNew) where T : Component { if (parent == null) { return(null); } T t = parent.GetComponentInChildren <T>(); if (t == null && ifNotExist == IfNotExist.AddNew) { t = AddChildComponent <T>(parent); } return(t); }
public static T GetComponent <T>(GameObject gameObject, IfNotExist ifNotExist = IfNotExist.AddNew) where T : Component { if (gameObject == null) { return(null); } T t = gameObject.GetComponent <T>(); if (t == null && ifNotExist == IfNotExist.AddNew) { t = AddComponent <T>(gameObject); } return(t); }
public static T[] GetChildComponents <T>(GameObject parent, bool includeInactive, IfNotExist ifNotExist = IfNotExist.AddNew) where T : Component { if (parent == null) { return(null); } T[] t = parent.GetComponentsInChildren <T>(includeInactive); if (t == null && ifNotExist == IfNotExist.AddNew) { t = new T[1]; t[0] = AddChildComponent <T>(parent); } return(t); }