2018-10-04 05:25:09 +08:00
|
|
|
|
namespace UnityEngine.UI.Extensions
|
2018-10-04 05:19:56 +08:00
|
|
|
|
{
|
2018-10-04 05:25:09 +08:00
|
|
|
|
public static class ExtentionMethods
|
2018-10-04 05:19:56 +08:00
|
|
|
|
{
|
2018-10-04 05:25:09 +08:00
|
|
|
|
public static T GetOrAddComponent<T>(this GameObject child) where T : Component
|
2018-10-04 05:19:56 +08:00
|
|
|
|
{
|
2018-10-04 05:25:09 +08:00
|
|
|
|
T result = child.GetComponent<T>();
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
result = child.AddComponent<T>();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2018-10-04 05:19:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|