using UnityEditor; /// <summary> /// UnityEngine.Object 型の拡張メソッドを管理するクラス /// </summary> public static class UnityEngineObjectExt { /// <summary> /// 指定されたオブジェクトがプレハブの場合 true を返します /// </summary> public static bool IsPrefab( this UnityEngine.Object self ) { var type = PrefabUtility.GetPrefabType( self ); return type == PrefabType.Prefab || type == PrefabType.ModelPrefab || type == PrefabType.PrefabInstance || type == PrefabType.ModelPrefabInstance || type == PrefabType.PrefabInstance ; } }
if ( gameObject.IsPrefab() )
{
...
}