Beispiel #1
0
        /// <summary>
        /// Sets the <see cref="GestureId"/> <paramref name="gestureId"/> for this control.
        /// </summary>
        /// <param name="gestureId"></param>
        public void SetGestureId(GestureId gestureId)
        {
            Assert.AreNotEqual(gestureId, GestureId.None);

            _gestureId      = gestureId;
            _labelText.text = _gestureId.ToString().Nicify().ToUpper();
        }
Beispiel #2
0
        /// <summary>
        /// Loads the states configuration and creates all necessary state objects
        /// </summary>
        /// <param name="config">The configuration node</param>
        private void LoadThresholds(XmlDocument config)
        {
            DTWRecognizer.ThresholdSettings generalSettings = null;
            config.ProcessXmlNodes("//configuration/gestureSettings",
                                   settings =>
            {
                generalSettings = DTWRecognizer.ThresholdSettings.CreateFromXML(settings, false);
            });

            config.ProcessXmlNodes("//configuration/gestureSettings/gestureSetting",
                                   settings =>
            {
                GestureId gestureId = (GestureId)int.Parse(settings.Attributes["gesture"].Value);

                if (!this.Gestures.ContainsKey(gestureId))
                {
                    throw new InvalidDataException(string.Format("Gesture {0} is not specified in the gestures section of the config file",
                                                                 gestureId.ToString()));
                }

                this.GestureSettings[gestureId] = DTWRecognizer.ThresholdSettings.CreateFromXML(settings);
            });

            // make sure all gestures have their settings
            foreach (GestureId gestureId in this.Gestures.Keys)
            {
                if (gestureId != GestureId.Unknown)
                {
                    bool hasOwnSettings = this.GestureSettings.ContainsKey(gestureId);
                    if (!hasOwnSettings)
                    {
                        if (generalSettings != null)
                        {
                            this.GestureSettings[gestureId] = generalSettings;
                        }
                        else
                        {
                            throw new InvalidDataException(string.Format("Gesture {0} has no own settings and no general settings exist!", gestureId.ToString()));
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Loads the gesture to eventid mapping
        /// </summary>
        /// <param name="config">The configuration node</param>
        private void LoadGestureTransitions(XmlDocument config)
        {
            config.ProcessXmlNodes("//configuration/gesturetransitions/gesturetransition",
                                   transition =>
            {
                FSMStateId fromStateId = (FSMStateId)int.Parse(transition.Attributes["fromState"].Value);
                GestureId gestureId    = (GestureId)int.Parse(transition.Attributes["onGesture"].Value);
                FSMEventId eventId     = (FSMEventId)int.Parse(transition.Attributes["raiseStateEvent"].Value);

                if (!this.Gestures.ContainsKey(gestureId))
                {
                    throw new InvalidDataException(string.Format("Gesture {0} is not specified in the gestures section of the config file",
                                                                 gestureId.ToString()));
                }

                if (!this.States.ContainsKey(fromStateId))
                {
                    throw new InvalidDataException(string.Format("State {0} is not specified in the states section of the config file",
                                                                 fromStateId.ToString()));
                }

                this.GestureTransitions[new KeyValuePair <FSMStateId, GestureId>(fromStateId, gestureId)] = eventId;
            });
        }
Beispiel #4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            GUI.changed = false;

            AppIntentProfile profile = target as AppIntentProfile;

            if (profile == null)
            {
                // Nothing we can do, so give up.
                return;
            }

            // Sensors
            EditorGUILayout.LabelField(SensorsLabel, EditorStyles.boldLabel);
            _newSensors.Clear();
            bool sensorsChanged = false;

            for (int i = 0; i < WearableConstants.SensorIds.Length; i++)
            {
                SensorId id = WearableConstants.SensorIds[i];

                bool prior = profile.GetSensorInProfile(id);
                bool post  = EditorGUILayout.Toggle(id.ToString(), prior, WearableConstants.EmptyLayoutOptions);
                sensorsChanged |= prior != post;

                if (post)
                {
                    _newSensors.Add(id);
                }
            }

            if (sensorsChanged)
            {
                profile.SetSensorIntent(_newSensors);
            }

            // Intervals
            GUILayoutTools.LineSeparator();
            EditorGUILayout.LabelField(IntervalsLabel, EditorStyles.boldLabel);
            _newIntervals.Clear();
            bool intervalsChanged = false;

            for (int i = 0; i < WearableConstants.UpdateIntervals.Length; i++)
            {
                SensorUpdateInterval interval = WearableConstants.UpdateIntervals[i];
                string label = string.Format(
                    IntervalFormat,
                    ((int)WearableTools.SensorUpdateIntervalToMilliseconds(interval)).ToString());
                bool prior = profile.GetIntervalInProfile(interval);
                bool post  = EditorGUILayout.Toggle(label, prior, WearableConstants.EmptyLayoutOptions);
                intervalsChanged |= prior != post;

                if (post)
                {
                    _newIntervals.Add(interval);
                }
            }

            if (intervalsChanged)
            {
                profile.SetIntervalIntent(_newIntervals);
            }


            // Gestures
            GUILayoutTools.LineSeparator();
            EditorGUILayout.LabelField(GesturesLabel, EditorStyles.boldLabel);

            _newGestures.Clear();
            bool gesturesChanged = false;

            for (int i = 0; i < WearableConstants.GestureIds.Length; i++)
            {
                GestureId id = WearableConstants.GestureIds[i];

                if (id == GestureId.None)
                {
                    continue;
                }

                bool prior = profile.GetGestureInProfile(id);
                bool post  = EditorGUILayout.Toggle(id.ToString(), prior, WearableConstants.EmptyLayoutOptions);
                gesturesChanged |= prior != post;

                if (post)
                {
                    _newGestures.Add(id);
                }
            }

            if (gesturesChanged)
            {
                profile.SetGestureIntent(_newGestures);
            }

            if (HasDeviceSpecificGesturesEnabled(profile))
            {
                EditorGUILayout.HelpBox(WearableConstants.DeviceSpecificGestureDiscouragedWarning, MessageType.Warning);
            }

            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            GUI.changed = false;

            AppIntentProfile profile = target as AppIntentProfile;

            if (profile == null)
            {
                // Nothing we can do, so give up.
                return;
            }

            // Sensors
            EditorGUILayout.LabelField(SENSORS_LABEL, EditorStyles.boldLabel);
            _newSensors.Clear();
            bool sensorsChanged = false;

            for (int i = 0; i < WearableConstants.SENSOR_IDS.Length; i++)
            {
                SensorId id = WearableConstants.SENSOR_IDS[i];

                bool prior = profile.GetSensorInProfile(id);
                bool post  = EditorGUILayout.Toggle(id.ToString(), prior, WearableEditorConstants.EMPTY_LAYOUT_OPTIONS);
                sensorsChanged |= prior != post;

                if (post)
                {
                    _newSensors.Add(id);
                }
            }

            if (sensorsChanged)
            {
                profile.SetSensorIntent(_newSensors);
            }

            // Intervals
            GUILayoutTools.LineSeparator();
            EditorGUILayout.LabelField(INTERVALS_LABEL, EditorStyles.boldLabel);
            _newIntervals.Clear();
            bool intervalsChanged = false;

            for (int i = 0; i < WearableConstants.UPDATE_INTERVALS.Length; i++)
            {
                SensorUpdateInterval interval = WearableConstants.UPDATE_INTERVALS[i];
                string label = string.Format(
                    INTERVAL_FORMAT,
                    ((int)WearableTools.SensorUpdateIntervalToMilliseconds(interval)).ToString());
                bool prior = profile.GetIntervalInProfile(interval);
                bool post  = EditorGUILayout.Toggle(label, prior, WearableEditorConstants.EMPTY_LAYOUT_OPTIONS);
                intervalsChanged |= prior != post;

                if (post)
                {
                    _newIntervals.Add(interval);
                }
            }

            if (intervalsChanged)
            {
                profile.SetIntervalIntent(_newIntervals);
            }


            // Gestures
            GUILayoutTools.LineSeparator();
            EditorGUILayout.LabelField(GESTURES_LABEL, EditorStyles.boldLabel);

            _newGestures.Clear();
            bool gesturesChanged = false;

            for (int i = 0; i < WearableConstants.GESTURE_IDS.Length; i++)
            {
                GestureId id = WearableConstants.GESTURE_IDS[i];

                if (id == GestureId.None)
                {
                    continue;
                }

                bool prior = profile.GetGestureInProfile(id);
                bool post  = EditorGUILayout.Toggle(id.ToString(), prior, WearableEditorConstants.EMPTY_LAYOUT_OPTIONS);
                gesturesChanged |= prior != post;

                if (post)
                {
                    _newGestures.Add(id);
                }
            }

            if (gesturesChanged)
            {
                profile.SetGestureIntent(_newGestures);
            }

            if (HasDeviceSpecificGesturesEnabled(profile))
            {
                EditorGUILayout.HelpBox(WearableEditorConstants.DEVICE_SPECIFIC_GESTURE_DISCOURAGED_WARNING, MessageType.Warning);
            }

            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }