/
EnumMask.cs
executable file
路44 lines (30 loc) 路 1.04 KB
/
EnumMask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace CandyCoded
{
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(Enum))]
#endif
// ReSharper disable once RequiredBaseTypesIsNotInherited
public class EnumMaskAttribute : PropertyAttribute
{
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(EnumMaskAttribute))]
public class EnumMaskDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var enumValue = (Enum)fieldInfo.GetValue(property.serializedObject.targetObject);
EditorGUI.BeginProperty(position, label, property);
var enumNew = EditorGUI.EnumFlagsField(position, label, enumValue);
property.intValue = (int)Convert.ChangeType(enumNew, enumValue.GetType());
EditorGUI.EndProperty();
}
}
#endif
}