You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
857 B

  1. using UnityEngine;
  2. #if UNITY_EDITOR
  3. using UnityEditor;
  4. #endif
  5. public class HideInPrefabAttribute : PropertyAttribute
  6. {
  7. }
  8. [CustomPropertyDrawer(typeof(HideInPrefabAttribute))]
  9. public class HideInPrefabDrawer : PropertyDrawer
  10. {
  11. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  12. {
  13. PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject);
  14. if (type != PrefabType.Prefab)
  15. EditorGUI.PropertyField(position, property, label);
  16. }
  17. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  18. {
  19. PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject);
  20. if (type == PrefabType.Prefab)
  21. return 0;
  22. return base.GetPropertyHeight(property, label);
  23. }
  24. }