Beispiel #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            EditorGUI.BeginProperty(position, label, property);

            GUI.Box(position, GUIContent.none);
            Rect line = new Rect(
                position.x,
                position.y + TopPadding,
                position.width,
                WearableConstants.SingleLineHeight);


            var          statusValueProp = property.FindPropertyRelative(StatusValuesField);
            DeviceStatus status          = statusValueProp.intValue;

            for (int i = 0; i < Flags.Length; i++)
            {
                DeviceStatusFlags flag = Flags[i];
                if (flag == DeviceStatusFlags.None ||
                    flag == DeviceStatusFlags.SensorServiceSuspended)
                {
                    continue;
                }

                using (new EditorGUI.DisabledScope(flag == DeviceStatusFlags.SensorServiceSuspended))
                {
                    bool value = EditorGUI.Toggle(
                        line,
                        flag.ToString(),
                        status.GetFlagValue(flag));

                    status.SetFlagValue(flag, value);
                }

                line.y += WearableConstants.SingleLineHeight;
            }
            statusValueProp.intValue = status;

            EditorGUI.EndProperty();
            property.serializedObject.ApplyModifiedProperties();
            EditorGUI.indentLevel = indent;
        }
Beispiel #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            EditorGUI.BeginProperty(position, label, property);
            Rect line = new Rect(
                position.x,
                position.y,
                position.width,
                WearableEditorConstants.SINGLE_LINE_HEIGHT);

            // Device Status
            EditorGUI.LabelField(line, DEVICE_STATUS_HEADING);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;

            Rect box = new Rect(
                line.x,
                line.y,
                line.width,
                line.height * (WearableConstants.DEVICE_STATUS_FLAGS.Length - 2));                 // Flag count less "None" and "Suspended"

            GUI.Box(box, GUIContent.none);

            var          statusValueProp = property.FindPropertyRelative(STATUS_VALUES_FIELD);
            DeviceStatus status          = statusValueProp.intValue;

            for (int i = 0; i < WearableConstants.DEVICE_STATUS_FLAGS.Length; i++)
            {
                DeviceStatusFlags flag = WearableConstants.DEVICE_STATUS_FLAGS[i];
                if (flag == DeviceStatusFlags.None ||
                    flag == DeviceStatusFlags.SensorServiceSuspended)
                {
                    continue;
                }

                using (new EditorGUI.DisabledScope(flag == DeviceStatusFlags.SensorServiceSuspended))
                {
                    bool value = EditorGUI.Toggle(
                        line,
                        flag.ToString(),
                        status.GetFlagValue(flag));

                    status.SetFlagValue(flag, value);
                }

                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            }
            statusValueProp.intValue = status;


            // Transmission period
            // No-op

            // ANR header
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT * 0.5f;
            EditorGUI.LabelField(line, ANR_HEADING);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            box     = new Rect(
                line.x,
                line.y,
                line.width,
                WearableEditorConstants.SINGLE_LINE_HEIGHT * (WearableConstants.ACTIVE_NOISE_REDUCTION_MODES.Length + 1));
            GUI.Box(box, GUIContent.none);


            // ANR current mode (read-only)
            using (new EditorGUI.DisabledScope(true))
            {
                var anrModeProperty = property.FindPropertyRelative(CURRENT_ANR_MODE_FIELD);
                var anrMode         = (ActiveNoiseReductionMode)anrModeProperty.intValue;
                EditorGUI.LabelField(line, CURRENT_ANR_MODE_LABEL, anrMode.ToString());
                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            }

            // ANR available modes
            EditorGUI.LabelField(line, AVAILABLE_ANR_MODES_HEADING);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;

            EditorGUI.indentLevel++;
            var availableAnrModesProperty = property.FindPropertyRelative(AVAILABLE_ANR_MODES_FIELD);
            int oldAnrModes = availableAnrModesProperty.intValue;
            int newAnrModes = 0;

            for (int i = 0; i < WearableConstants.ACTIVE_NOISE_REDUCTION_MODES.Length; i++)
            {
                ActiveNoiseReductionMode mode = WearableConstants.ACTIVE_NOISE_REDUCTION_MODES[i];

                if (mode == ActiveNoiseReductionMode.Invalid)
                {
                    continue;
                }

                int  flag     = (1 << (int)mode);
                bool selected = EditorGUI.Toggle(line, mode.ToString(), (flag & oldAnrModes) != 0);
                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
                if (selected)
                {
                    newAnrModes |= flag;
                }
            }

            EditorGUI.indentLevel--;

            if (newAnrModes != oldAnrModes)
            {
                availableAnrModesProperty.intValue = newAnrModes;
            }

            // CNC header
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT * 0.5f;
            EditorGUI.LabelField(line, CNC_HEADING);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            box     = new Rect(
                line.x,
                line.y,
                line.width,
                WearableEditorConstants.SINGLE_LINE_HEIGHT * 3);
            GUI.Box(box, GUIContent.none);

            using (new EditorGUI.DisabledScope(true))
            {
                // CNC Level (read-only)
                var cncLevelProperty = property.FindPropertyRelative(CNC_LEVEL_FIELD);
                EditorGUI.LabelField(line, CNC_LEVEL_LABEL_TEXT, cncLevelProperty.intValue.ToString());
                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;

                // CNC Enabled (read-only)
                var cncEnabledProperty = property.FindPropertyRelative(CNC_ENABLED_FIELD);
                EditorGUI.Toggle(line, CNC_ENABLED_LABEL, cncEnabledProperty.boolValue);
                line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            }

            // Total CNC levels
            var totalCncLevelsProperty = property.FindPropertyRelative(TOTAL_CNC_LEVELS_FIELD);

            EditorGUI.PropertyField(line, totalCncLevelsProperty, _totalCncLevelsLabel);
            line.y += WearableEditorConstants.SINGLE_LINE_HEIGHT;
            if (totalCncLevelsProperty.intValue < 0)
            {
                totalCncLevelsProperty.intValue = 0;
            }

            EditorGUI.EndProperty();
            property.serializedObject.ApplyModifiedProperties();
            EditorGUI.indentLevel = indent;
        }