Beispiel #1
0
 public void ReconsiderHapticsByDevice(HapticDevice deviceToReconsider)
 {
     if (ignoreHapticDevices.Contains(deviceToReconsider))
     {
         ignoreHapticDevices.Remove(deviceToReconsider);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Allows the manager to know that a device is able to target a specific body part
 /// </summary>
 /// <param name="device">The haptic device that is able to target a body coordinate</param>
 /// <param name="hitLocation">The body coordinate system that it can handle</param>
 public void AddDevicePerBodyLocation(HapticDevice device, ScriptableBodyCoordinate hitLocation)
 {
     if (bodyAffectedByDevice.ContainsKey(hitLocation.affectableBodyParts))
     {
         bodyAffectedByDevice[hitLocation.affectableBodyParts].Add(device);
     }
     else
     {
         bodyAffectedByDevice[hitLocation.affectableBodyParts] = new List <HapticDevice>
         {
             device
         };
     }
 }
Beispiel #3
0
 public void IgnoreHapticsByDevice(HapticDevice deviceToIgnore)
 {
     ignoreHapticDevices.Add(deviceToIgnore);
 }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            // Check to see if the dictionary is set up, if not, then work cannot be done
            if (hapticSystemAndDevices == null)
            {
                Awake();
            }

            // Reads the latest values on the current (serialized) object (i.e., the one that is selected)
            serializedObject.Update();

            // Ask if they want the visualizer attached
            useVisualizer = EditorGUILayout.Toggle("Visualize Haptics", useVisualizer);

            if (useVisualizer)
            {
                HapticVisualizer attachedVisualizer = targetManager.gameObject.GetComponent <HapticVisualizer>();

                if (attachedVisualizer == null)
                {
                    targetManager.gameObject.AddComponent <HapticVisualizer>();
                }
            }
            else
            {
                HapticVisualizer attachedVisualizer = targetManager.gameObject.GetComponent <HapticVisualizer>();

                if (attachedVisualizer != null)
                {
                    DestroyImmediate(attachedVisualizer);
                }
            }

            foreach (var hapticDevice in hapticSystemAndDevices)
            {
                hapticSystemEditorInfo[hapticDevice.Key].isFoldedOut = EditorGUILayout.Foldout(hapticSystemEditorInfo[hapticDevice.Key].isFoldedOut, hapticDevice.Key);

                if (hapticSystemEditorInfo[hapticDevice.Key].isFoldedOut)
                {
                    // Display each haptic device
                    foreach (HapticDeviceInfo currentDevice in hapticSystemAndDevices[hapticDevice.Key])
                    {
                        currentDevice.isSelected = EditorGUILayout.Toggle(currentDevice.systemAttribute.DeviceName, currentDevice.isSelected);
                    }
                }

                // Save values to the editor prefs
                for (int n = 0; n < hapticDevice.Value.Count; n++)
                {
                    // Add/remove any scripts that have changed
                    if (EditorPrefs.GetBool(Constants.EditorPrefLocation + hapticDevice.Key + "." + hapticDevice.Value[n].systemAttribute.DeviceName) != hapticDevice.Value[n].isSelected)
                    {
                        // Add component
                        if (hapticDevice.Value[n].isSelected)
                        {
                            GameObject deviceSystemObject = GameObject.Find(hapticDevice.Key);

                            if (deviceSystemObject == null)
                            {
                                deviceSystemObject = new GameObject(hapticDevice.Key);
                                deviceSystemObject.transform.parent = (target as HapticManager).transform;
                            }

                            GameObject deviceObject = new GameObject(hapticDevice.Value[n].systemAttribute.DeviceName);
                            deviceObject.transform.parent = deviceSystemObject.transform;

                            HapticDevice deviceInfo = deviceObject.AddComponent(hapticDevice.Value[n].deviceType) as HapticDevice;
                            deviceInfo.ApplyDefaultData(hapticDevice.Value[n].systemAttribute);
                        }
                        // Remove component
                        else
                        {
                            GameObject objToRemove = GameObject.Find(hapticDevice.Key + "/" + hapticDevice.Value[n].systemAttribute.DeviceName);

                            if (objToRemove != null)
                            {
                                GameObject parentObj = objToRemove.transform.parent.gameObject;

                                DestroyImmediate(objToRemove);

                                if (parentObj.transform.childCount == 0)
                                {
                                    DestroyImmediate(parentObj);
                                }
                            }
                        }
                    }

                    // Write to EditorPrefs so the used devices are saved
                    EditorPrefs.SetBool(Constants.EditorPrefLocation + hapticDevice.Key + "." + hapticDevice.Value[n].systemAttribute.DeviceName, hapticDevice.Value[n].isSelected);
                }
            }

            EditorPrefs.SetBool(Constants.EditorPrefLocation + "UseVisualizer", useVisualizer);

            // Write properties back to the serialized object
            serializedObject.ApplyModifiedProperties();
        }