Exemplo n.º 1
0
        public BitMask(BitMask mask)
        {
            Assert.IsNotNull(mask);

            _numFlags = mask._numFlags;
            _bytes    = new byte[mask._bytes.Length];

            for (int i = 0; i < _numFlags; i++)
            {
                _bytes[i] = mask._bytes[i];
            }
        }
Exemplo n.º 2
0
        public static BitMask EnumMask <T>(bool defaultValue = false) where T : struct, IComparable, IConvertible, IFormattable
        {
            DebugUtils.AssertIsEnumType <T>();

            BitMask mask = new BitMask(EnumUtils.GetCount(typeof(T)));

            if (defaultValue)
            {
                mask.SetAllFlags(true);
            }

            return(mask);
        }
Exemplo n.º 3
0
        public static BitMask EnumMask <T>(params T[] setEnumValues) where T : struct, IComparable, IConvertible, IFormattable
        {
            DebugUtils.AssertIsEnumType <T>();

            BitMask mask = new BitMask(EnumUtils.GetCount(typeof(T)));

            for (int i = 0; i < setEnumValues.Length; i++)
            {
                mask.SetFlag((int)(object)setEnumValues[i], true);
            }

            return(mask);
        }
Exemplo n.º 4
0
        public override void OnGUI(Rect totalRect, SerializedProperty property, GUIContent label)
        {
            SerializedProperty numFlagsProperty  = property.FindPropertyRelative("_numFlags");
            SerializedProperty byteArrayProperty = property.FindPropertyRelative("_bytes");
            BitMask            bitMask           = property.GetValue <BitMask>();

            EditorGUI.BeginProperty(totalRect, label, property);
            Rect rect = new Rect(totalRect.x, totalRect.y, totalRect.width, EditorGUIUtility.singleLineHeight);

            property.isExpanded = EditorGUI.Foldout(new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height), property.isExpanded, label, true);
            EditorGUI.LabelField(new Rect(rect.x + EditorGUIUtility.labelWidth, rect.y, rect.width - EditorGUIUtility.labelWidth, rect.height), GetStatusLabel(bitMask));

            if (property.isExpanded)
            {
                EditorGUI.indentLevel++;
                rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

                if (!_isEnumMode)
                {
                    numFlagsProperty.intValue = Mathf.Max(0, EditorGUI.IntField(rect, "Length", numFlagsProperty.intValue));
                    rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                }
                else
                {
                    numFlagsProperty.intValue = _enumNames.Length;
                }

                Rect buttonRect = new Rect(rect.x + EditorGUIUtility.labelWidth, rect.y, (rect.width - EditorGUIUtility.labelWidth) * 0.5f, rect.height);
                if (GUI.Button(buttonRect, "NOTHING"))
                {
                    for (int i = 0; i < numFlagsProperty.intValue; i++)
                    {
                        SetFlag(i, false, byteArrayProperty);
                    }
                }

                buttonRect.x += buttonRect.width;
                if (GUI.Button(buttonRect, "EVERYTHING"))
                {
                    for (int i = 0; i < numFlagsProperty.intValue; i++)
                    {
                        SetFlag(i, true, byteArrayProperty);
                    }
                }

                if (numFlagsProperty.intValue != bitMask.NumFlags)
                {
                    Resize(numFlagsProperty.intValue, byteArrayProperty);
                }


                for (int i = 0; i < numFlagsProperty.intValue; i++)
                {
                    rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

                    bool oldValue = GetFlag(i, byteArrayProperty);
                    bool newValue = EditorGUI.Toggle(rect, _isEnumMode ? _enumNames[i] : "Flag " + i, oldValue);

                    if (oldValue != newValue)
                    {
                        SetFlag(i, newValue, byteArrayProperty);
                    }
                }
            }

            EditorGUI.EndProperty();
            _height = rect.y - totalRect.y + EditorGUIUtility.singleLineHeight;

            property.serializedObject.ApplyModifiedProperties();
        }