/// <summary> /// Loads all the objects in a given path, instantiates them then adds them as children /// </summary> /// <typeparam name="T">The type of the child to return</typeparam> /// <param name="parentObject">The parent object to add the children to</param> /// <param name="prefabsPath">The path from which to load the prefabs</param> /// <returns></returns> public static List <T> LoadAllAsChildren <T>(this GameObject parentObject, string prefabsPath) where T : Component { var prefabs = Resources.LoadAll <T>(prefabsPath); var children = new List <T>(); foreach (var prefab in prefabs) { var instance = UnityUtils.Instantiate <T>(prefab.gameObject); instance.transform.parent = parentObject.transform; children.Add(instance); } return(children); }
/// <summary> /// Instantiates an instance of this prefab and retuns a component on it /// </summary> /// <param name="obj"></param> /// <returns></returns> public static T Instantiate <T>(this GameObject prefab) where T : Component { return(UnityUtils.Instantiate <T>(prefab)); }
/// <summary> /// Instantiates an instance of this prefab /// </summary> /// <param name="obj"></param> /// <returns></returns> public static GameObject Instantiate(this GameObject prefab) { return(UnityUtils.Instantiate(prefab)); }