diff --git a/Editor/HumanoidControl/Extensions/Custom.meta b/Editor/HumanoidControl/Extensions/Custom.meta new file mode 100644 index 0000000..04bf143 --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Custom.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 693f9f816fd82f44283cd7bf2ed3ef93 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/HumanoidControl/Extensions/Custom/Custom_Editor.cs b/Editor/HumanoidControl/Extensions/Custom/Custom_Editor.cs new file mode 100644 index 0000000..faf4e20 --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Custom/Custom_Editor.cs @@ -0,0 +1,190 @@ +#if hCUSTOM +using UnityEditor; +using UnityEngine; + +namespace Passer.Humanoid { + using Passer.Tracking; + + public class Custom_Editor : Tracker_Editor { + + #region Tracker + + public class TrackerProps : HumanoidControl_Editor.HumanoidTrackerProps { + protected SerializedProperty bodySkeletonProp; + + public TrackerProps(SerializedObject serializedObject, HumanoidControl_Editor.HumanoidTargetObjs targetObjs, CustomTracker _custom) + : base(serializedObject, targetObjs, _custom, "custom") { + tracker = _custom; + + bodySkeletonProp = serializedObject.FindProperty(nameof(HumanoidControl.custom) + "." + nameof(HumanoidControl.custom.bodySkeleton)); + } + + public override void Inspector(HumanoidControl humanoid) { + Inspector(humanoid, "Custom"); + + if (humanoid.custom.enabled == false) + return; + + EditorGUI.indentLevel++; + bodySkeletonProp.objectReferenceValue = (BodySkeleton)EditorGUILayout.ObjectField("Body Skeleton", bodySkeletonProp.objectReferenceValue, typeof(BodySkeleton), true); + EditorGUI.indentLevel--; + } + } + + #endregion Tracker + + #region Head + + public class HeadTargetProps : HeadTarget_Editor.TargetProps { + protected SerializedProperty sensorProp; + + public HeadTargetProps(SerializedObject serializedObject, HeadTarget headTarget) + : base(serializedObject, headTarget.custom, headTarget, "custom") { + + sensorProp = serializedObject.FindProperty("custom.sensorComponent"); + } + + public override void Inspector() { + if (headTarget.humanoid.custom.enabled == false) + return; + + enabledProp.boolValue = HumanoidTarget_Editor.ControllerInspector(headTarget.custom, headTarget); + headTarget.custom.enabled = enabledProp.boolValue; + if (!Application.isPlaying) { + headTarget.custom.SetSensor2Target(); + headTarget.custom.ShowSensor(headTarget.humanoid.showRealObjects && headTarget.showRealObjects); + } + + if (enabledProp.boolValue) { + EditorGUI.indentLevel++; + if (sensorProp.objectReferenceValue == null && headTarget.custom.sensorComponent != null) + sensorProp.objectReferenceValue = headTarget.custom.sensorComponent; // sensorTransform.GetComponent(); + + sensorProp.objectReferenceValue = (SensorComponent)EditorGUILayout.ObjectField("Sensor", sensorProp.objectReferenceValue, typeof(SensorComponent), true); + + EditorGUI.indentLevel--; + } + } + } + + #endregion Head + + #region Hand + + public class HandTargetProps : HandTarget_Editor.TargetProps { + protected SerializedProperty sensorProp; + protected SerializedProperty attachedBoneProp; + + public HandTargetProps(SerializedObject serializedObject, HandTarget handTarget) + : base(serializedObject, handTarget.custom, handTarget, "custom") { + + sensorProp = serializedObject.FindProperty("custom.sensorComponent"); + attachedBoneProp = serializedObject.FindProperty("custom.attachedBone"); + } + + public override void Inspector() { + if (handTarget.humanoid.custom.enabled == false) + return; + + enabledProp.boolValue = HumanoidTarget_Editor.ControllerInspector(handTarget.custom, handTarget); + handTarget.custom.enabled = enabledProp.boolValue; + if (!Application.isPlaying) { + handTarget.custom.SetSensor2Target(); + handTarget.custom.ShowSensor(handTarget.humanoid.showRealObjects && handTarget.showRealObjects); + } + + if (enabledProp.boolValue) { + EditorGUI.indentLevel++; + if (sensorProp.objectReferenceValue == null && handTarget.custom.sensorComponent != null) + sensorProp.objectReferenceValue = handTarget.custom.sensorComponent; //.GetComponent(); + + sensorProp.objectReferenceValue = (SensorComponent)EditorGUILayout.ObjectField("Sensor", sensorProp.objectReferenceValue, typeof(SensorComponent), true); + attachedBoneProp.intValue = (int)(ArmBones)EditorGUILayout.EnumPopup("Bone", (ArmBones)attachedBoneProp.intValue); + + EditorGUI.indentLevel--; + } + } + } + + #endregion Hand + + #region Hips + + public class HipsTargetProps : HipsTarget_Editor.TargetProps { + protected SerializedProperty sensorProp; + protected SerializedProperty attachedBoneProp; + + public HipsTargetProps(SerializedObject serializedObject, HipsTarget hipsTarget) + : base(serializedObject, hipsTarget.custom, hipsTarget, "custom") { + + sensorProp = serializedObject.FindProperty("custom.sensorComponent"); + attachedBoneProp = serializedObject.FindProperty("custom.attachedBone"); + } + + public override void Inspector() { + if (hipsTarget.humanoid.custom.enabled == false) + return; + + enabledProp.boolValue = HumanoidTarget_Editor.ControllerInspector(hipsTarget.custom, hipsTarget); + hipsTarget.custom.enabled = enabledProp.boolValue; + if (!Application.isPlaying) { + hipsTarget.custom.SetSensor2Target(); + hipsTarget.custom.ShowSensor(hipsTarget.humanoid.showRealObjects && hipsTarget.showRealObjects); + } + + if (enabledProp.boolValue) { + EditorGUI.indentLevel++; + if (sensorProp.objectReferenceValue == null && hipsTarget.custom.sensorComponent != null) + sensorProp.objectReferenceValue = hipsTarget.custom.sensorComponent; //.GetComponent(); + + sensorProp.objectReferenceValue = (SensorComponent)EditorGUILayout.ObjectField("Sensor", sensorProp.objectReferenceValue, typeof(SensorComponent), true); + attachedBoneProp.intValue = (int)(TorsoBones)EditorGUILayout.EnumPopup("Bone", (TorsoBones)attachedBoneProp.intValue); + + EditorGUI.indentLevel--; + } + } + } + + #endregion Hips + + #region Foot + + public class FootTargetProps : FootTarget_Editor.TargetProps { + protected SerializedProperty sensorProp; + protected SerializedProperty attachedBoneProp; + + public FootTargetProps(SerializedObject serializedObject, FootTarget footTarget) + : base(serializedObject, footTarget.custom, footTarget, "custom") { + + sensorProp = serializedObject.FindProperty("custom.sensorComponent"); + attachedBoneProp = serializedObject.FindProperty("custom.attachedBone"); + } + + public override void Inspector() { + if (footTarget.humanoid.custom.enabled == false) + return; + + enabledProp.boolValue = HumanoidTarget_Editor.ControllerInspector(footTarget.custom, footTarget); + footTarget.custom.enabled = enabledProp.boolValue; + if (!Application.isPlaying) { + footTarget.custom.SetSensor2Target(); + footTarget.custom.ShowSensor(footTarget.humanoid.showRealObjects && footTarget.showRealObjects); + } + + if (enabledProp.boolValue) { + EditorGUI.indentLevel++; + if (sensorProp.objectReferenceValue == null && footTarget.custom.sensorComponent != null) + sensorProp.objectReferenceValue = footTarget.custom.sensorComponent; //.GetComponent(); + + sensorProp.objectReferenceValue = (SensorComponent)EditorGUILayout.ObjectField("Sensor", sensorProp.objectReferenceValue, typeof(SensorComponent), true); + attachedBoneProp.intValue = (int)(LegBones)EditorGUILayout.EnumPopup("Bone", (LegBones)attachedBoneProp.intValue); + + EditorGUI.indentLevel--; + } + } + } + + #endregion Foot + } +} +#endif \ No newline at end of file diff --git a/Editor/HumanoidControl/Extensions/Custom/Custom_Editor.cs.meta b/Editor/HumanoidControl/Extensions/Custom/Custom_Editor.cs.meta new file mode 100644 index 0000000..37a1498 --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Custom/Custom_Editor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 44d806c9717b1fa46a86f6a982c5e1b9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/HumanoidControl/Extensions/Oculus.meta b/Editor/HumanoidControl/Extensions/Oculus.meta new file mode 100644 index 0000000..dcbb67e --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Oculus.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 565c528cf57cf7b44bb215ac006b5c73 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/HumanoidControl/Extensions/Oculus/OculusObject_Editor.cs b/Editor/HumanoidControl/Extensions/Oculus/OculusObject_Editor.cs new file mode 100644 index 0000000..231733f --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Oculus/OculusObject_Editor.cs @@ -0,0 +1,70 @@ +/* +#if hOCULUS +using UnityEngine; +using UnityEditor; + +namespace Passer.Humanoid { + + public class OculusObject_Editor { + + #region Object Tracker + private enum Side { + Left, + Right + } + + public static void ObjectTrackerInspector(ObjectTracker objectTracker) { +//#if hOCULUS +//#if UNITY_STANDALONE_WIN +// bool wasEnabled = objectTracker.oculusTouch.enabled; +// SensorInspector(objectTracker.oculusTouch, "Oculus Touch"); +// if (!wasEnabled && objectTracker.oculusTouch.enabled) +// //objectTracker.oculusTouch.Start(objectTracker.humanoid, objectTracker.transform); + +// if (objectTracker.oculusTouch.enabled) { +// EditorGUI.indentLevel++; +// Side side = objectTracker.isLeft ? Side.Left : Side.Right; +// side = (Side)EditorGUILayout.EnumPopup("Controller side", side); +// objectTracker.isLeft = (side == Side.Left); + +// objectTracker.oculusTouch.CheckSensorTransform(); +// objectTracker.oculusTouch.SetSensor2Target(); + +// objectTracker.oculusTouch.sensorTransform = (Transform)EditorGUILayout.ObjectField("Tracker Transform", objectTracker.oculusTouch.sensorTransform, typeof(Transform), true); +// EditorGUI.indentLevel--; +// } +// else { +// objectTracker.oculusTouch.sensorTransform = Oculus_Editor.RemoveTransform(objectTracker.oculusTouch.sensorTransform); +// } +//#elif UNITY_ANDROID +// bool wasEnabled = objectTracker.oculusTouch.enabled; +// SensorInspector(objectTracker.oculusTouch, "Gear VR Controller"); +// if (!wasEnabled && objectTracker.oculusTouch.enabled) +// objectTracker.oculusTouch.Start(objectTracker.humanoid, objectTracker.transform); + +// if (objectTracker.oculusTouch.enabled) { +// EditorGUI.indentLevel++; +// Side side = objectTracker.isLeft ? Side.Left : Side.Right; +// side = (Side)EditorGUILayout.EnumPopup("Controller side", side); +// objectTracker.isLeft = (side == Side.Left); +// //objectTracker.gearVRController.sensorTransform = (Transform)EditorGUILayout.ObjectField("Tracker Transform", objectTracker.gearVRController.sensorTransform, typeof(Transform), true); +// EditorGUI.indentLevel--; +// } else { +// //objectTracker.gearVRController.sensorTransform = OculusTouch_Editor.RemoveOculusTracker(objectTracker.gearVRController.sensorTransform); +// } +//#endif +//#endif + } + + public static void SensorInspector(UnitySensor sensor, string name) { + EditorGUILayout.BeginHorizontal(); + sensor.enabled = EditorGUILayout.ToggleLeft(name, sensor.enabled, GUILayout.MinWidth(80)); + if (sensor.enabled && Application.isPlaying) + EditorGUILayout.EnumPopup(sensor.status); + EditorGUILayout.EndHorizontal(); + } + #endregion + } +} +#endif +*/ \ No newline at end of file diff --git a/Editor/HumanoidControl/Extensions/Oculus/OculusObject_Editor.cs.meta b/Editor/HumanoidControl/Extensions/Oculus/OculusObject_Editor.cs.meta new file mode 100644 index 0000000..a0d1b83 --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Oculus/OculusObject_Editor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d2b97881a82361047b0057dafb5be452 +timeCreated: 1530177518 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/HumanoidControl/Extensions/Oculus/OculusTracker_Editor.cs b/Editor/HumanoidControl/Extensions/Oculus/OculusTracker_Editor.cs new file mode 100644 index 0000000..8faf3ab --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Oculus/OculusTracker_Editor.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace Passer.Humanoid { + using Passer.Tracking; + + [CustomEditor(typeof(Passer.Tracking.Oculus))] + public class OculusTracker_Editor : Editor { + + public override void OnInspectorGUI() { + serializedObject.Update(); + + PersistentTrackingInspector(); + + serializedObject.ApplyModifiedProperties(); + } + + protected virtual void PersistentTrackingInspector() { + SerializedProperty persistentTrackingProp = serializedObject.FindProperty("persistentTracking"); + persistentTrackingProp.boolValue = EditorGUILayout.Toggle("Persistent Tracking", persistentTrackingProp.boolValue); + + if (persistentTrackingProp.boolValue) { + EditorGUI.indentLevel++; + RealWorldConfigurationInspector(); + EditorGUI.indentLevel--; + } + } + + protected virtual void RealWorldConfigurationInspector() { + SerializedProperty realWorldConfigurationProp = serializedObject.FindProperty("realWorldConfiguration"); + EditorGUILayout.ObjectField(realWorldConfigurationProp); + RealWorldConfiguration configuration = (RealWorldConfiguration)realWorldConfigurationProp.objectReferenceValue; + + if (configuration == null) { + EditorGUILayout.HelpBox("Real World Configuration is required for persistent Tracking", MessageType.Warning); + return; + } + + RealWorldConfiguration.TrackingSpace trackingSpace = + configuration.trackers.Find(space => space.trackerId == TrackerId.Oculus); + if (trackingSpace == null) + return; + + Passer.Tracking.Oculus tracker = (Passer.Tracking.Oculus) serializedObject.targetObject; + tracker.transform.position = trackingSpace.position; + tracker.transform.rotation = trackingSpace.rotation; + } + } +} \ No newline at end of file diff --git a/Editor/HumanoidControl/Extensions/Oculus/OculusTracker_Editor.cs.meta b/Editor/HumanoidControl/Extensions/Oculus/OculusTracker_Editor.cs.meta new file mode 100644 index 0000000..a519d53 --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Oculus/OculusTracker_Editor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d6ea259c2e931ad4881c602c46a1a8b1 +timeCreated: 1562140542 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/HumanoidControl/Extensions/Oculus/Oculus_Editor.cs b/Editor/HumanoidControl/Extensions/Oculus/Oculus_Editor.cs new file mode 100644 index 0000000..58fd6b3 --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Oculus/Oculus_Editor.cs @@ -0,0 +1,396 @@ +/* +using System.IO; +using UnityEditor; +using UnityEngine; +using UnityEngine.XR; +using Passer.Tracking; + +namespace Passer { + using Humanoid; + + public class Oculus_Editor : Tracker_Editor { + +#if hOCULUS && (UNITY_STANDALONE_WIN || UNITY_ANDROID) + +#if UNITY_ANDROID && hOCHAND + private readonly static System.Version minHandTrackingVersion = new System.Version(1, 44, 0); +#endif + + #region Tracker + + public class TrackerProps : HumanoidControl_Editor.HumanoidTrackerProps { + + private readonly SerializedProperty trackerProp; +#if UNITY_ANDROID + SerializedProperty deviceTypeProp; + SerializedProperty handTrackingProp; +#endif + + public TrackerProps(SerializedObject serializedObject, HumanoidControl_Editor.HumanoidTargetObjs targetObjs, OculusTracker _oculus) + : base(serializedObject, targetObjs, _oculus, "oculus") { + tracker = _oculus; + + trackerProp = serializedObject.FindProperty("oculus.tracker"); + + if (targetObjs.headTargetObj != null) + headSensorProp = targetObjs.headTargetObj.FindProperty(nameof(HumanoidControl.oculus)); + if (targetObjs.leftHandTargetObj != null) + leftHandSensorProp = targetObjs.leftHandTargetObj.FindProperty(nameof(HumanoidControl.oculus)); + if (targetObjs.rightHandTargetObj != null) + rightHandSensorProp = targetObjs.rightHandTargetObj.FindProperty(nameof(HumanoidControl.oculus)); + +#if UNITY_ANDROID && !UNITY_2020_1_OR_NEWER + handTrackingProp = serializedObject.FindProperty("oculus.handTracking"); + //deviceTypeProp = serializedObject.FindProperty("oculus.androidDeviceType"); + + //OculusHumanoidTracker.AndroidDeviceType androidDeviceType = (OculusHumanoidTracker.AndroidDeviceType)deviceTypeProp.intValue; + //if (androidDeviceType == OculusHumanoidTracker.AndroidDeviceType.OculusQuest) + // CheckQuestManifest(); +#endif + } + + public override void Inspector(HumanoidControl humanoid) { + //bool oculusSupported = OculusSupported(); + //if (oculusSupported) { + // humanoid.oculus.CheckTracker(humanoid); + // humanoid.headTarget.oculus.CheckSensor(humanoid.headTarget); + // humanoid.leftHandTarget.oculus.CheckSensor(humanoid.leftHandTarget); + // humanoid.rightHandTarget.oculus.CheckSensor(humanoid.rightHandTarget); +#if !pUNITYXR + Inspector(humanoid, "Oculus"); + + if (enabledProp.boolValue) { + EditorGUI.indentLevel++; + if (trackerProp.objectReferenceValue == null) { + // Tracker does not exit + using (new EditorGUILayout.HorizontalScope()) { + EditorGUILayout.LabelField("Tracker", GUILayout.Width(120)); + if (GUILayout.Button("Show")) { + humanoid.oculus.CheckTracker(humanoid); + } + } + } + else + trackerProp.objectReferenceValue = (Oculus)EditorGUILayout.ObjectField("Tracker", trackerProp.objectReferenceValue, typeof(Oculus), true); + EditorGUI.indentLevel--; + } +#if UNITY_ANDROID && hOCHAND && !UNITY_2020_1_OR_NEWER + EditorGUI.indentLevel++; + deviceTypeProp.intValue = (int)(OculusHumanoidTracker.AndroidDeviceType)EditorGUILayout.EnumPopup("Device Type", (OculusHumanoidTracker.AndroidDeviceType)deviceTypeProp.intValue); + handTrackingProp.boolValue = EditorGUILayout.Toggle("Hand Tracking", handTrackingProp.boolValue); +#if UNITY_EDITOR_OSX + if (handTrackingProp.boolValue) { + EditorGUILayout.HelpBox( + "Hand tracking required at least OVR Plugin version 1.44 or higher\n" + + "Install the latetest version using the Oculus Integration package", + MessageType.Warning); + } +#else + if (handTrackingProp.boolValue && !(Humanoid.Tracking.OculusDevice.version >= minHandTrackingVersion)) { + EditorGUILayout.HelpBox( + "Hand tracking required at least OVR Plugin version 1.44 or higher\n" + + "Install the latetest version using the Oculus Integration package", + MessageType.Error); + } +#endif + EditorGUI.indentLevel--; +#endif + //} + //else + // enabledProp.boolValue = false; +#endif + } + + protected virtual void CheckQuestManifest() { + string manifestPath = Application.dataPath + "/Plugins/Android/AndroidManifest.xml"; + FileInfo fileInfo = new FileInfo(manifestPath); + fileInfo.Directory.Create(); + bool manifestAvailable = File.Exists(manifestPath); + if (manifestAvailable) + return; + + string humanoidPath = Configuration_Editor.FindHumanoidFolder(); + string questManifestPath = Application.dataPath + humanoidPath + "Extensions/Oculus/QuestManifest.xml"; + File.Copy(questManifestPath, manifestPath); + } + } + + #endregion + + #region Head + + public class HeadTargetProps : HeadTarget_Editor.TargetProps { + + + private readonly SerializedProperty hmdProp; + SerializedProperty overrideOptitrackPositionProp; + + public HeadTargetProps(SerializedObject serializedObject, HeadTarget headTarget) + : base(serializedObject, headTarget.oculus, headTarget, "oculus") { + + hmdProp = serializedObject.FindProperty("oculus.hmd"); + overrideOptitrackPositionProp = serializedObject.FindProperty("oculus.overrideOptitrackPosition"); + } + + public override void Inspector() { + if (!headTarget.humanoid.oculus.enabled) + return; + + enabledProp.boolValue = HumanoidTarget_Editor.ControllerInspector(headTarget.oculus, headTarget); + headTarget.oculus.enabled = enabledProp.boolValue; + + if (enabledProp.boolValue) { + EditorGUI.indentLevel++; + if (headTarget.oculus.hmd == null) { + // Hmd does not exist + using (new EditorGUILayout.HorizontalScope()) { + EditorGUILayout.LabelField("Hmd", GUILayout.Width(120)); + if (GUILayout.Button("Show")) { + headTarget.oculus.CheckSensor(headTarget); + } + } + } + else + hmdProp.objectReferenceValue = (OculusHmd)EditorGUILayout.ObjectField("Hmd", hmdProp.objectReferenceValue, typeof(OculusHmd), true); +#if hOPTITRACK + if (headTarget.optitrack.enabled) + overrideOptitrackPositionProp.boolValue = EditorGUILayout.Toggle("Override OptiTrack Position", overrideOptitrackPositionProp.boolValue); + else +#endif + overrideOptitrackPositionProp.boolValue = true; + + EditorGUI.indentLevel--; + } + else + headTarget.oculus.CheckSensor(headTarget); + + } + } + + #region HMD Component + [CustomEditor(typeof(OculusHmd))] + public class OculusHmdComponent_Editor : Editor { + OculusHmd sensorComponent; + + private void OnEnable() { + sensorComponent = (OculusHmd)target; + } + + public override void OnInspectorGUI() { + serializedObject.Update(); + + EditorGUI.BeginDisabledGroup(true); + EditorGUILayout.EnumPopup("Status", sensorComponent.status); + EditorGUILayout.FloatField("Position Confidence", sensorComponent.positionConfidence); + EditorGUILayout.FloatField("Rotation Confidence", sensorComponent.rotationConfidence); + EditorGUI.EndDisabledGroup(); + + serializedObject.ApplyModifiedProperties(); + } + } + #endregion + + #endregion + + #region Hand + public class HandTargetProps : HandTarget_Editor.TargetProps { + +#if UNITY_ANDROID && hOCHAND + SerializedProperty handTrackingProp; + SerializedProperty skeletonProp; +#endif +#if pUNITYXR + SerializedProperty controllerProp; +#endif + + public HandTargetProps(SerializedObject serializedObject, HandTarget handTarget) + : base(serializedObject, handTarget.oculus, handTarget, "oculus") { + +#if UNITY_ANDROID && hOCHAND + handTrackingProp = serializedObject.FindProperty("oculus.handTracking"); + skeletonProp = serializedObject.FindProperty("oculus.handSkeleton"); +#endif +#if pUNITYXR + controllerProp = serializedObject.FindProperty("oculus.unityXRController"); +#endif + } + + public override void Inspector() { + if (!handTarget.humanoid.oculus.enabled || !OculusSupported()) + return; + +#if !pUNITYXR + CheckControllerComponent(handTarget); +#if UNITY_ANDROID && hOCHAND + handTarget.oculus.CheckSensor(handTarget, handTarget.humanoid.oculus); +#endif + + enabledProp.boolValue = HumanoidTarget_Editor.ControllerInspector(handTarget.oculus, handTarget); + handTarget.oculus.enabled = enabledProp.boolValue; +#if !pUNITYXR + handTarget.oculus.CheckSensorTransform(); +#endif + if (!Application.isPlaying) { + handTarget.oculus.SetSensor2Target(); + handTarget.oculus.ShowSensor(handTarget.humanoid.showRealObjects && handTarget.showRealObjects); + } + + if (enabledProp.boolValue) { + EditorGUI.indentLevel++; +#if pUNITYXR + controllerProp.objectReferenceValue = (UnityXRController)EditorGUILayout.ObjectField("Controller", controllerProp.objectReferenceValue, typeof(UnityXRController), true); +#else + sensorTransformProp.objectReferenceValue = (Transform)EditorGUILayout.ObjectField("Tracker Transform", handTarget.oculus.sensorTransform, typeof(Transform), true); +#endif +#if UNITY_ANDROID && hOCHAND + if (handTarget.humanoid.oculus.handTracking) { + skeletonProp.objectReferenceValue = (OculusHandSkeleton)EditorGUILayout.ObjectField("Skeleton", skeletonProp.objectReferenceValue, typeof(OculusHandSkeleton), true); + } +#endif + EditorGUI.indentLevel--; + } +#endif + } + + protected static void CheckControllerComponent(HandTarget handTarget) { + if (handTarget.oculus.sensorTransform == null) + return; + +#if pUNITYXR + // UnityXRController controller = handTarget.oculus.sensorTransform.GetComponent(); + // if (controller == null) + // controller = handTarget.oculus.sensorTransform.gameObject.AddComponent(); + // controller.isLeft = handTarget.isLeft; + //#else + OculusController sensorComponent = handTarget.oculus.sensorTransform.GetComponent(); + if (sensorComponent == null) + sensorComponent = handTarget.oculus.sensorTransform.gameObject.AddComponent(); + sensorComponent.isLeft = handTarget.isLeft; +#endif + } + + //#if hOCHAND + // protected static void CheckSkeletonComponent(HandTarget handTarget) { + // if (handTarget.oculus.handSkeleton == null) { + // handTarget.oculus.handSkeleton = handTarget.oculus.FindHandSkeleton(handTarget.isLeft); + // if (handTarget.oculus.handSkeleton == null) + // handTarget.oculus.handSkeleton = handTarget.oculus.CreateHandSkeleton(handTarget.isLeft, handTarget.showRealObjects); + // } + + // } + //#endif + } + #region Controller Component + [CustomEditor(typeof(OculusController))] + public class OculusControllerComponent_Editor : Editor { + OculusController controllerComponent; + + private void OnEnable() { + controllerComponent = (OculusController)target; + } + + public override void OnInspectorGUI() { + serializedObject.Update(); + + EditorGUI.BeginDisabledGroup(true); + EditorGUILayout.EnumPopup("Status", controllerComponent.status); + EditorGUILayout.FloatField("Position Confidence", controllerComponent.positionConfidence); + EditorGUILayout.FloatField("Rotation Confidence", controllerComponent.rotationConfidence); + EditorGUILayout.Space(); + EditorGUILayout.Toggle("Is Left", controllerComponent.isLeft); + EditorGUILayout.Vector3Field("Joystick", controllerComponent.primaryAxis); + EditorGUILayout.Slider("Index Trigger", controllerComponent.trigger1, -1, 1); + EditorGUILayout.Slider("Hand Trigger", controllerComponent.trigger2, -1, 1); + if (controllerComponent.isLeft) { + EditorGUILayout.Slider("Button X", controllerComponent.button1, -1, 1); + EditorGUILayout.Slider("Button Y", controllerComponent.button2, -1, 1); + } + else { + EditorGUILayout.Slider("Button A", controllerComponent.button1, -1, 1); + EditorGUILayout.Slider("Button B", controllerComponent.button2, -1, 1); + } + EditorGUILayout.Slider("Thumbrest", controllerComponent.button3, -1, 1); + EditorGUI.EndDisabledGroup(); + + serializedObject.ApplyModifiedProperties(); + } + } + #endregion + #endregion + + #region Object Target + + private static SerializedProperty objectEnabledProp; + private static SerializedProperty objectSensorTransformProp; + private static SerializedProperty objectSensor2TargetPositionProp; + private static SerializedProperty objectSensor2TargetRotationProp; + + public static void InitObject(SerializedObject serializedObject, ObjectTarget objectTarget) { + objectEnabledProp = serializedObject.FindProperty("oculusController.enabled"); + objectSensorTransformProp = serializedObject.FindProperty("oculusController.sensorTransform"); + objectSensor2TargetPositionProp = serializedObject.FindProperty("oculusController.sensor2TargetPosition"); + objectSensor2TargetRotationProp = serializedObject.FindProperty("oculusController.sensor2TargetRotation"); + + objectTarget.oculus.Init(objectTarget); + } + + private enum LeftRight { + Left, + Right + } + + public static void ObjectInspector(OculusController controller) { + objectEnabledProp.boolValue = Target_Editor.ControllerInspector(controller); + controller.CheckSensorTransform(); + + if (objectEnabledProp.boolValue) { + EditorGUI.indentLevel++; + LeftRight leftRight = controller.isLeft ? LeftRight.Left : LeftRight.Right; + leftRight = (LeftRight)EditorGUILayout.EnumPopup("Tracker Id", leftRight); + controller.isLeft = leftRight == LeftRight.Left; + objectSensorTransformProp.objectReferenceValue = (Transform)EditorGUILayout.ObjectField("Tracker Transform", controller.sensorTransform, typeof(Transform), true); + EditorGUI.indentLevel--; + } + } + + public static void SetSensor2Target(OculusController controller) { + controller.SetSensor2Target(); + objectSensor2TargetRotationProp.quaternionValue = controller.sensor2TargetRotation; + objectSensor2TargetPositionProp.vector3Value = controller.sensor2TargetPosition; + } + + #endregion +#endif + public static bool OculusSupported() { +#if pUNITYXR + return true; +#else + string[] supportedDevices = XRSettings.supportedDevices; + foreach (string supportedDevice in supportedDevices) { + if (supportedDevice == "Oculus") + return true; + } + return false; +#endif + } + + } + +#if !hOCULUS + [InitializeOnLoad] + public class OculusCleanup { + + // Cleanup Oculus devices when Oculus is disabled in the preferences + static OculusCleanup() { + OculusHmd[] hmds = Object.FindObjectsOfType(); + foreach (OculusHmd hmd in hmds) + Object.DestroyImmediate(hmd.gameObject, true); + + OculusController[] controllers = Object.FindObjectsOfType(); + foreach (OculusController controller in controllers) + Object.DestroyImmediate(controller.gameObject, true); + } + } +#endif +} +*/ \ No newline at end of file diff --git a/Editor/HumanoidControl/Extensions/Oculus/Oculus_Editor.cs.meta b/Editor/HumanoidControl/Extensions/Oculus/Oculus_Editor.cs.meta new file mode 100644 index 0000000..43708ed --- /dev/null +++ b/Editor/HumanoidControl/Extensions/Oculus/Oculus_Editor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 35c29c2d27bfad041b62b94717b32a5f +timeCreated: 1475155546 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: