using UnityEngine;
namespace UVC.Util
{
///
/// Unity¿¡¼ ÇÁ¸®ÆÕ °æ·Î¸¦ ÅëÇØ GameObject¸¦ »ý¼ºÇϰųª ƯÁ¤ ÄÄÆ÷³ÍÆ®¸¦ °¡Á®¿À´Â À¯Æ¿¸®Æ¼ Ŭ·¡½ºÀÔ´Ï´Ù.
///
public static class GameObjectUtil
{
///
/// ÁÖ¾îÁø ÇÁ¸®ÆÕ °æ·Î¸¦ ÅëÇØ GameObject¸¦ »ý¼ºÇÕ´Ï´Ù.
///
/// ÇÁ¸®ÆÕÀÇ Resources °æ·Î
/// »ý¼ºµÈ GameObjectÀÇ ºÎ¸ð Transform (¼±Åà »çÇ×)
/// »ý¼ºµÈ GameObject
///
///
/// string prefabPath = "Prefabs/MyPrefab";
/// GameObject newObject = prefabPath.GetGameObjectFromPrefabPath();
///
///
public static GameObject GetGameObjectFromPrefabPath(this string prefabPath, Transform parent = null)
{
GameObject prefab = Resources.Load(prefabPath, typeof(GameObject)) as GameObject;
return UnityEngine.Object.Instantiate(prefab, parent);
}
///
/// ÁÖ¾îÁø ÇÁ¸®ÆÕ °æ·Î¸¦ ÅëÇØ ƯÁ¤ ŸÀÔÀÇ ÄÄÆ÷³ÍÆ®¸¦ °¡Á®¿É´Ï´Ù.
///
/// °¡Á®¿Ã ÄÄÆ÷³ÍÆ® ŸÀÔ
/// ÇÁ¸®ÆÕÀÇ Resources °æ·Î
/// »ý¼ºµÈ GameObjectÀÇ ºÎ¸ð Transform (¼±Åà »çÇ×)
/// »ý¼ºµÈ GameObject¿¡¼ °¡Á®¿Â ÄÄÆ÷³ÍÆ®
///
///
/// string prefabPath = "Prefabs/MyPrefab";
/// MyComponent component = prefabPath.GetComponentFromPrefabPath();
///
///
public static T GetComponentFromPrefabPath(this string prefabPath, Transform parent = null)
{
GameObject prefab = Resources.Load(prefabPath, typeof(GameObject)) as GameObject;
GameObject go = UnityEngine.Object.Instantiate(prefab, parent);
return go.GetComponent();
}
}
}