using UnityEngine;
namespace TinaX
{
public static class TransformExtends
{
///
/// 获取Component,如果不存在就新建
///
///
///
public static T GetComponentOrAdd(this Transform obj) where T : Component
{
var t = obj.GetComponent();
if (t == null)
t = obj.gameObject.AddComponent();
return t;
}
///
/// 获取Component,如果不存在就新建
///
///
/// Component type
///
public static Component GetComponentOrAdd(this Transform obj, System.Type type)
{
var c = obj.GetComponent(type);
if (c == null)
c = obj.gameObject.AddComponent(type);
return c;
}
}
}