using UnityEngine; using UnityEditor; [CustomPropertyDrawer(typeof(PrefabFieldAttribute))] public class PrefabFieldDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){ if(property.objectReferenceValue != null){ var prefabAssetType = PrefabUtility.GetPrefabAssetType(property.objectReferenceValue); switch(prefabAssetType){ case PrefabAssetType.Regular: case PrefabAssetType.Model: case PrefabAssetType.Variant: break; default: // Prefab以外がアタッチされた場合アタッチを外す property.objectReferenceValue = null; break; } } label.text += " (Prefab Only)"; EditorGUI.PropertyField(position, property, label); } }