ComponentRestrictionDrawer.cs 567 B

123456789101112131415161718192021
  1. using UnityEngine;
  2. using UnityEditor;
  3. [CustomPropertyDrawer(typeof(ComponentRestrictionAttribute))]
  4. public class ComponentRestrictionDrawer : PropertyDrawer
  5. {
  6. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  7. {
  8. var restriction = (ComponentRestrictionAttribute)attribute;
  9. if (property.propertyType == SerializedPropertyType.ObjectReference)
  10. {
  11. EditorGUI.ObjectField(position, property, restriction.type);
  12. }
  13. else
  14. {
  15. EditorGUI.PropertyField(position, property);
  16. }
  17. }
  18. } // class ComponentRestrictionDrawer