hogeのTransformのときに
hoge.gameObject.AddComponent <UILabel>();
っていちいち「.gameObject」を挟んで行うのは面倒だ。
hoge.AddComponent <UILabel>();
とやっても、AddComponentができるように拡張したい。
・CSTransform.cs
using UnityEngine; public static class CSTransform { public static T AddComponent <T> (this Transform transform) where T : Component { return transform.gameObject.AddComponent <T> (); } }
これを書いた.csファイルを「plugins」フォルダに追加してやればいい。