SHARE
TWEET

Untitled

a guest Mar 25th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Multi-Select enum property on Unity Inspector
  2.  
  3. **EnumFlagsAttribute.cs**
  4. ```cs
  5. using UnityEngine;
  6. using System.Collections;
  7.  
  8. public class EnumFlagsAttribute : PropertyAttribute {
  9.     public EnumFlagsAttribute() {}
  10. }
  11. ```
  12.  
  13. **EnumFlagsAttributeDrawer.cs**
  14. ```cs
  15. using System;
  16. using System.Collections;
  17. using UnityEngine;
  18. using UnityEditor;
  19.  
  20. [CustomPropertyDrawer(typeof(EnumFlagsAttribute))]
  21. public class EnumFlagsAttributeDrawer : PropertyDrawer {
  22.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
  23.         property.intValue = EditorGUI.MaskField(position, label, property.intValue, property.enumNames);
  24.     }
  25. }
  26. ```
  27.  
  28. **SampleEnumInspector.cs**
  29. ```cs
  30. using System;
  31. using UnityEngine;
  32.  
  33. public class SampleEnumInspector : Monobehaviour {
  34.   [EnumFlagsAttribute] public SampleEnum sampleEnum;
  35.  
  36.   public enum SampleEnum {
  37.     enumValue_1,
  38.     enumValue_2,
  39.     enumValue_3,
  40.     enumValue_4
  41.   }
  42. }
  43. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top