51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace UVC.Util
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Unity<74><79><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>θ<EFBFBD> <20><><EFBFBD><EFBFBD> GameObject<63><74> <20><><EFBFBD><EFBFBD><EFBFBD>ϰų<CFB0> Ư<><C6AF> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ƿ<EFBFBD><C6BF>Ƽ Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.
|
|||
|
|
/// </summary>
|
|||
|
|
public static class GameObjectUtil
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>־<EFBFBD><D6BE><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>θ<EFBFBD> <20><><EFBFBD><EFBFBD> GameObject<63><74> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="prefabPath"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Resources <20><><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="parent"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GameObject<63><74> <20>θ<EFBFBD> Transform (<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)</param>
|
|||
|
|
/// <returns><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GameObject</returns>
|
|||
|
|
/// <example>
|
|||
|
|
/// <code>
|
|||
|
|
/// string prefabPath = "Prefabs/MyPrefab";
|
|||
|
|
/// GameObject newObject = prefabPath.GetGameObjectFromPrefabPath();
|
|||
|
|
/// </code>
|
|||
|
|
/// </example>
|
|||
|
|
public static GameObject GetGameObjectFromPrefabPath(this string prefabPath, Transform parent = null)
|
|||
|
|
{
|
|||
|
|
GameObject prefab = Resources.Load(prefabPath, typeof(GameObject)) as GameObject;
|
|||
|
|
return UnityEngine.Object.Instantiate(prefab);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>־<EFBFBD><D6BE><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>θ<EFBFBD> <20><><EFBFBD><EFBFBD> Ư<><C6AF> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD>ɴϴ<C9B4>.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <typeparam name="T"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ Ÿ<><C5B8></typeparam>
|
|||
|
|
/// <param name="prefabPath"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Resources <20><><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="parent"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GameObject<63><74> <20>θ<EFBFBD> Transform (<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)</param>
|
|||
|
|
/// <returns><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GameObject<63><74><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ</returns>
|
|||
|
|
/// <example>
|
|||
|
|
/// <code>
|
|||
|
|
/// string prefabPath = "Prefabs/MyPrefab";
|
|||
|
|
/// MyComponent component = prefabPath.GetComponentFromPrefabPath<MyComponent>();
|
|||
|
|
/// </code>
|
|||
|
|
/// </example>
|
|||
|
|
public static T GetComponentFromPrefabPath<T>(this string prefabPath, Transform parent = null)
|
|||
|
|
{
|
|||
|
|
GameObject prefab = Resources.Load(prefabPath, typeof(GameObject)) as GameObject;
|
|||
|
|
GameObject go = UnityEngine.Object.Instantiate(prefab);
|
|||
|
|
if (parent != null) go.transform.SetParent(parent, false);
|
|||
|
|
return go.GetComponent<T>();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|