ソースコード
using UnityEngine; public static class UnityEngineObjectExtensions { public static T Clone<T>( this T self ) where T : Component { return Object.Instantiate( self ); } public static T CloneInParent<T>( this T self ) where T : Component { return Object.Instantiate( self, self.transform.parent ); } }
使用例
// デフォルト
var clone = Instantiate( original, original.transform.parent );
// 拡張メソッド
var clone = original.CloneInParent();