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.

53 lines
1.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. using UnityEngine;
  2. #if UNITY_EDITOR
  3. using UnityEditor;
  4. #endif
  5. /// <summary>
  6. /// Class for the Hide in Prefab Attribute
  7. /// </summary>
  8. /// <remarks>
  9. /// Class is empty because we have no parameters needed for this attribute
  10. /// </remarks>
  11. public class HideInPrefabAttribute : PropertyAttribute
  12. {
  13. }
  14. #if UNITY_EDITOR
  15. /// <summary>
  16. /// Override for the Property Drawer which draws the GUI
  17. /// </summary>
  18. [CustomPropertyDrawer(typeof(HideInPrefabAttribute))]
  19. public class HideInPrefabDrawer : PropertyDrawer
  20. {
  21. //On GUI override
  22. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  23. {
  24. //get the type of the object this property is attched to
  25. PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject);
  26. //if the type isn't a perfab then draw the property
  27. if (type != PrefabType.Prefab)
  28. EditorGUI.PropertyField(position, property, label);
  29. }
  30. //Override GetPropertyHeight
  31. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  32. {
  33. //get the type of the object this property is attched to
  34. PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject);
  35. //if type prefab return zero height (because it won't be drawn)
  36. if (type == PrefabType.Prefab)
  37. return 0;
  38. //else return normal height
  39. return base.GetPropertyHeight(property, label);
  40. }
  41. }
  42. #endif