initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4209e16f276e327468a3bba1ee24a3dd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,80 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if ENABLE_VR || ENABLE_AR
|
||||
using UnityEngine.XR.LegacyInputHelpers;
|
||||
|
||||
namespace UnityEditor.XR.LegacyInputHelpers
|
||||
{
|
||||
[CustomEditor(typeof(ArmModel))]
|
||||
internal class ArmModelEditor : Editor
|
||||
{
|
||||
|
||||
protected static class ArmModelStyles
|
||||
{
|
||||
public static GUIContent poseSourceLabel = EditorGUIUtility.TrTextContent("Input Pose Source", "The source of the 3dof controller data");
|
||||
public static GUIContent headPositionSourceLabel = EditorGUIUtility.TrTextContent("Head Position Source", "The source of head position data used by the arm model");
|
||||
public static GUIContent isLockedToNeckLabel = EditorGUIUtility.TrTextContent("Lock To Neck", "If true, the root of the pose is locked to the local position of the player's neck");
|
||||
public static GUIContent armExtensionOffsetLabel = EditorGUIUtility.TrTextContent("Arm Extension Offset", "Offset applied to the elbow position as the controller is rotated upwards");
|
||||
public static GUIContent elbowBendRatioLabel = EditorGUIUtility.TrTextContent("Elbow Bend Ratio", "Amount of the controller's rotation to apply to the elbow");
|
||||
|
||||
public static GUIContent elbowRestPositionLabel = EditorGUIUtility.TrTextContent("Elbow","The Elbow's Position relative to the users head");
|
||||
public static GUIContent wristRestPositionLabel = EditorGUIUtility.TrTextContent("Wrist","The Wrist's Position relative to the users head");
|
||||
public static GUIContent controllerRestPositionLabel = EditorGUIUtility.TrTextContent("Controller", "The Controller position relative to the users head");
|
||||
|
||||
public static GUIContent restPositionLabel = EditorGUIUtility.TrTextContent("Rest Position");
|
||||
}
|
||||
|
||||
protected SerializedProperty m_PoseSourceProp = null;
|
||||
protected SerializedProperty m_HeadGameObjectProp = null;
|
||||
protected SerializedProperty m_IsLockedToNeckProp = null;
|
||||
protected SerializedProperty m_ArmExtensionOffsetProp = null;
|
||||
protected SerializedProperty m_EblowRestPositionProp = null;
|
||||
protected SerializedProperty m_WristRestPositionProp = null;
|
||||
protected SerializedProperty m_ControllerRestPositionProp = null;
|
||||
protected SerializedProperty m_ElbowBendRatioProp = null;
|
||||
|
||||
protected bool m_ExpandRestPosition = false;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
|
||||
m_PoseSourceProp = this.serializedObject.FindProperty("m_PoseSource");
|
||||
m_HeadGameObjectProp = this.serializedObject.FindProperty("m_HeadPoseSource");
|
||||
m_IsLockedToNeckProp = this.serializedObject.FindProperty("m_IsLockedToNeck");
|
||||
m_ArmExtensionOffsetProp = this.serializedObject.FindProperty("m_ElbowRestPosition");
|
||||
m_EblowRestPositionProp = this.serializedObject.FindProperty("m_ElbowRestPosition");
|
||||
m_WristRestPositionProp = this.serializedObject.FindProperty("m_WristRestPosition");
|
||||
m_ControllerRestPositionProp = this.serializedObject.FindProperty("m_ControllerRestPosition");
|
||||
m_ElbowBendRatioProp = this.serializedObject.FindProperty("m_ElbowBendRatio");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(m_PoseSourceProp, ArmModelStyles.poseSourceLabel);
|
||||
EditorGUILayout.PropertyField(m_HeadGameObjectProp, ArmModelStyles.headPositionSourceLabel);
|
||||
EditorGUILayout.PropertyField(m_ArmExtensionOffsetProp, ArmModelStyles.armExtensionOffsetLabel);
|
||||
EditorGUILayout.PropertyField(m_ElbowBendRatioProp, ArmModelStyles.elbowBendRatioLabel);
|
||||
EditorGUILayout.PropertyField(m_IsLockedToNeckProp, ArmModelStyles.isLockedToNeckLabel);
|
||||
m_ExpandRestPosition = EditorGUILayout.Foldout(m_ExpandRestPosition,ArmModelStyles.restPositionLabel);
|
||||
if (m_ExpandRestPosition)
|
||||
{
|
||||
using (EditorGUI.IndentLevelScope indent = new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_EblowRestPositionProp, ArmModelStyles.elbowRestPositionLabel);
|
||||
EditorGUILayout.PropertyField(m_WristRestPositionProp, ArmModelStyles.wristRestPositionLabel);
|
||||
EditorGUILayout.PropertyField(m_ControllerRestPositionProp, ArmModelStyles.controllerRestPositionLabel);
|
||||
}
|
||||
|
||||
}
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fd661411ada16794aa7015ddf3778407
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,106 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
#if ENABLE_VR || ENABLE_AR
|
||||
using UnityEngine.XR.LegacyInputHelpers;
|
||||
|
||||
namespace UnityEditor.XR.LegacyInputHelpers
|
||||
{
|
||||
[CustomEditor(typeof(SwingArmModel))]
|
||||
internal class SwingArmModelEditor : ArmModelEditor
|
||||
{
|
||||
|
||||
protected static class SwingArmModelStyles
|
||||
{
|
||||
public static GUIContent rotationRatioLabel = EditorGUIUtility.TrTextContent("Rotation Ratio");
|
||||
public static GUIContent shoulderRotationRatioLabel = EditorGUIUtility.TrTextContent("Shoulder", "Portion of controller rotation applied to the shoulder joint");
|
||||
public static GUIContent elbowRotationRatioLabel = EditorGUIUtility.TrTextContent("Elbow", "Portion of controller rotation applied to the elbow joint");
|
||||
public static GUIContent wristRotationRatioLabel = EditorGUIUtility.TrTextContent("Wrist", "Portion of controller rotation applied to the wrist joint");
|
||||
|
||||
public static GUIContent shiftedRotationRatioLabel = EditorGUIUtility.TrTextContent("Shifted Rotation Ratio");
|
||||
public static GUIContent shiftedShoulderRotationRatioLabel = EditorGUIUtility.TrTextContent("Shifted Shoulder","Portion of controller rotation applied to the shoulder joint when the controller is backwards");
|
||||
public static GUIContent shiftedElbowRotationRatioLabel = EditorGUIUtility.TrTextContent("Shifted Elbow", "Portion of controller rotation applied to the elbow joint when the controller is backwards");
|
||||
public static GUIContent shiftedWristRotationRatioLabel = EditorGUIUtility.TrTextContent("Shifted Wrist", "Portion of controller rotation applied to the wrist joint when the controller is backwards");
|
||||
|
||||
public static GUIContent jointShiftAngleLabel = EditorGUIUtility.TrTextContent("Joint Shift Angle", "The min/max angle of the controller before starting to lerp towards the shifted joint ratios");
|
||||
public static GUIContent jointShiftExponentLabel = EditorGUIUtility.TrTextContent("Joint Shift Exponent", "Exponent applied to the joint shift ratio to control the curve of the shift");
|
||||
}
|
||||
|
||||
SerializedProperty m_ShoulderRotationRatioProp = null;
|
||||
SerializedProperty m_EblowRotationRatioProp = null;
|
||||
SerializedProperty m_WristRotationRatioProp = null;
|
||||
SerializedProperty m_ShiftedShoulderRotationRatioProp = null;
|
||||
SerializedProperty m_ShiftedEblowRotationRatioProp = null;
|
||||
SerializedProperty m_ShiftedWristRotationRatioProp = null;
|
||||
SerializedProperty m_JointShiftAngleProp = null;
|
||||
SerializedProperty m_JointShiftExponentProp = null;
|
||||
|
||||
bool m_ExpandShoulder = false;
|
||||
bool m_ExpandShiftedShoulder = false;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
m_ShoulderRotationRatioProp = this.serializedObject.FindProperty("m_ShoulderRotationRatio");
|
||||
m_EblowRotationRatioProp = this.serializedObject.FindProperty("m_ElbowRotationRatio");
|
||||
m_WristRotationRatioProp = this.serializedObject.FindProperty("m_WristRotationRatio");
|
||||
m_ShiftedShoulderRotationRatioProp = this.serializedObject.FindProperty("m_ShiftedShoulderRotationRatio");
|
||||
m_ShiftedEblowRotationRatioProp = this.serializedObject.FindProperty("m_ShiftedElbowRotationRatio");
|
||||
m_ShiftedWristRotationRatioProp = this.serializedObject.FindProperty("m_ShiftedWristRotationRatio");
|
||||
m_JointShiftAngleProp = this.serializedObject.FindProperty("m_JointShiftAngle");
|
||||
m_JointShiftExponentProp = this.serializedObject.FindProperty("m_JointShiftExponent");
|
||||
}
|
||||
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(m_PoseSourceProp, ArmModelStyles.poseSourceLabel);
|
||||
EditorGUILayout.PropertyField(m_HeadGameObjectProp, ArmModelStyles.headPositionSourceLabel);
|
||||
EditorGUILayout.PropertyField(m_ArmExtensionOffsetProp, ArmModelStyles.armExtensionOffsetLabel);
|
||||
EditorGUILayout.PropertyField(m_JointShiftAngleProp, SwingArmModelStyles.jointShiftAngleLabel);
|
||||
EditorGUILayout.PropertyField(m_JointShiftExponentProp, SwingArmModelStyles.jointShiftExponentLabel);
|
||||
EditorGUILayout.PropertyField(m_ElbowBendRatioProp, ArmModelStyles.elbowBendRatioLabel);
|
||||
EditorGUILayout.PropertyField(m_IsLockedToNeckProp, ArmModelStyles.isLockedToNeckLabel);
|
||||
|
||||
m_ExpandRestPosition = EditorGUILayout.Foldout(m_ExpandRestPosition, ArmModelStyles.restPositionLabel);
|
||||
if (m_ExpandRestPosition)
|
||||
{
|
||||
using (EditorGUI.IndentLevelScope indent = new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_EblowRestPositionProp, ArmModelStyles.elbowRestPositionLabel);
|
||||
EditorGUILayout.PropertyField(m_WristRestPositionProp, ArmModelStyles.wristRestPositionLabel);
|
||||
EditorGUILayout.PropertyField(m_ControllerRestPositionProp, ArmModelStyles.controllerRestPositionLabel);
|
||||
}
|
||||
|
||||
}
|
||||
m_ExpandShoulder = EditorGUILayout.Foldout(m_ExpandShoulder, SwingArmModelStyles.rotationRatioLabel);
|
||||
if (m_ExpandShoulder)
|
||||
{
|
||||
using (EditorGUI.IndentLevelScope indent = new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_ShoulderRotationRatioProp, SwingArmModelStyles.shoulderRotationRatioLabel);
|
||||
EditorGUILayout.PropertyField(m_EblowRotationRatioProp, SwingArmModelStyles.elbowRotationRatioLabel);
|
||||
EditorGUILayout.PropertyField(m_WristRotationRatioProp, SwingArmModelStyles.wristRotationRatioLabel);
|
||||
}
|
||||
}
|
||||
m_ExpandShiftedShoulder = EditorGUILayout.Foldout(m_ExpandShiftedShoulder, SwingArmModelStyles.shiftedRotationRatioLabel);
|
||||
if (m_ExpandShiftedShoulder)
|
||||
{
|
||||
using (EditorGUI.IndentLevelScope indent = new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_ShiftedShoulderRotationRatioProp, SwingArmModelStyles.shiftedShoulderRotationRatioLabel);
|
||||
EditorGUILayout.PropertyField(m_ShiftedEblowRotationRatioProp, SwingArmModelStyles.shiftedElbowRotationRatioLabel);
|
||||
EditorGUILayout.PropertyField(m_ShiftedWristRotationRatioProp, SwingArmModelStyles.shiftedWristRotationRatioLabel);
|
||||
}
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 759b8a665f0e4234db4a1b9a1514aa1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,46 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
#if ENABLE_VR || ENABLE_AR
|
||||
using UnityEngine.XR.LegacyInputHelpers;
|
||||
|
||||
namespace UnityEditor.XR.LegacyInputHelpers
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(TransitionArmModel))]
|
||||
internal class TransitionArmModelEditor : Editor
|
||||
{
|
||||
static class Styles
|
||||
{
|
||||
public static GUIContent poseSourceLabel = EditorGUIUtility.TrTextContent("Angular Velocity Source", "The source of angular velocity which is used to transition to queued arm models");
|
||||
public static GUIContent armModelSourceLabel = EditorGUIUtility.TrTextContent("Current Arm Model", "The current arm model ");
|
||||
public static GUIContent armModelTransitions = EditorGUIUtility.TrTextContent("Configuration", "Arm models that the transition arm model can blend to when receiving the event corresponding to the transition");
|
||||
}
|
||||
|
||||
SerializedProperty m_PoseSourceProp = null;
|
||||
SerializedProperty m_ArmModelProp = null;
|
||||
SerializedProperty m_ArmModelTransitions = null;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
m_PoseSourceProp = this.serializedObject.FindProperty("m_PoseSource");
|
||||
m_ArmModelProp = this.serializedObject.FindProperty("m_CurrentArmModelComponent");
|
||||
m_ArmModelTransitions = this.serializedObject.FindProperty("m_ArmModelTransitions");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.PropertyField(m_PoseSourceProp, Styles.poseSourceLabel);
|
||||
EditorGUILayout.PropertyField(m_ArmModelProp, Styles.armModelSourceLabel);
|
||||
EditorGUILayout.PropertyField(m_ArmModelTransitions, Styles.armModelTransitions,true);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d0771c912c4d7c841b238a454ec571cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
#if ENABLE_VR || ENABLE_AR
|
||||
using UnityEngine.XR;
|
||||
|
||||
namespace UnityEditor.XR.LegacyInputHelpers
|
||||
{
|
||||
[CustomEditor(typeof(CameraOffset))]
|
||||
class CameraOffsetHelperEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.ObjectField("Script", MonoScript.FromMonoBehaviour((CameraOffset)target), typeof(CameraOffset), false);
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_CameraFloorOffsetObject"));
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_RequestedTrackingMode"));
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_CameraYOffset"));
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e42439f4b5dbd1947a2161c0c2969508
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"name": "UnityEditor.XR.LegacyInputHelpers",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UnityEngine.XR.LegacyInputHelpers",
|
||||
"UnityEngine.SpatialTracking",
|
||||
"Unity.RenderPipelines.HighDefinition.Runtime",
|
||||
"Unity.RenderPipelines.Universal.Runtime",
|
||||
"Unity.InputSystem"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.xr.interaction.toolkit",
|
||||
"expression": "0.9.0",
|
||||
"define": "XRI_PRESENT"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.high-definition",
|
||||
"expression": "1.0.0",
|
||||
"define": "HDRP_PRESENT"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.universal",
|
||||
"expression": "1.0.0",
|
||||
"define": "URP_PRESENT"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.universal",
|
||||
"expression": "[10.0.0,10.1.0)",
|
||||
"define": "URP_PRESENT_10_0"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.universal",
|
||||
"expression": "10.1.0",
|
||||
"define": "URP_PRESENT_10_1_OR_NEWER"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.high-definition",
|
||||
"expression": "[10.0.0,10.1.0)",
|
||||
"define": "HDRP_PRESENT_10_0"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.high-definition",
|
||||
"expression": "10.1.0",
|
||||
"define": "HDRP_PRESENT_10_1_OR_NEWER"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.inputsystem",
|
||||
"expression": "1.0.0",
|
||||
"define": "ISX_PRESENT"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 52c867deb3832554c84dc4202bd47258
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,203 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
#if URP_PRESENT
|
||||
using UnityEngine.Rendering.Universal;
|
||||
#endif
|
||||
|
||||
#if HDRP_PRESENT
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
#endif
|
||||
|
||||
#if ENABLE_VR || ENABLE_AR
|
||||
using UnityEngine.SpatialTracking;
|
||||
#if XRI_PRESENT
|
||||
#else
|
||||
|
||||
namespace UnityEditor.XR.LegacyInputHelpers
|
||||
{
|
||||
|
||||
internal static class MenuUtils
|
||||
{
|
||||
static readonly string kMainCamera = "MainCamera";
|
||||
static readonly Vector3 kDefaultCameraPosition = new Vector3(0.0f, 1.0f, -10.0f);
|
||||
const float kDefaultCameraNearClip = 0.01f;
|
||||
|
||||
static bool CreateSimpleXRRig(Camera xrCamera, out GameObject gameObj)
|
||||
{
|
||||
var xrRigGO = ObjectFactory.CreateGameObject("XRRig");
|
||||
var cameraOffsetGO = ObjectFactory.CreateGameObject("Camera Offset");
|
||||
|
||||
|
||||
Undo.SetTransformParent(cameraOffsetGO.transform, xrRigGO.transform, "Parent Camera Offset to XR Rig");
|
||||
Pose camPose = new Pose();
|
||||
// we only want to move the rig to the camera position if one is passed in.
|
||||
bool camExistsAndNeedsMoving = false;
|
||||
if (xrCamera == null)
|
||||
{
|
||||
var xrCameraGO = ObjectFactory.CreateGameObject("Main Camera", typeof(Camera));
|
||||
xrCamera = xrCameraGO.GetComponent<Camera>();
|
||||
}
|
||||
else
|
||||
{
|
||||
camPose.position = xrCamera.transform.position;
|
||||
// if initial camera position, move to the floor
|
||||
if(camPose.position == kDefaultCameraPosition)
|
||||
{
|
||||
camPose.position.y = 0.0f;
|
||||
}
|
||||
camPose.rotation = xrCamera.transform.rotation;
|
||||
camExistsAndNeedsMoving = true;
|
||||
}
|
||||
Undo.SetTransformParent(xrCamera.transform, cameraOffsetGO.transform, "Parent Camera to Camera Offset");
|
||||
|
||||
// Override the near clip to better handle controllers near the face
|
||||
xrCamera.nearClipPlane = kDefaultCameraNearClip;
|
||||
|
||||
xrCamera.transform.localPosition = Vector3.zero;
|
||||
xrCamera.transform.localRotation = Quaternion.identity;
|
||||
xrCamera.tag = kMainCamera;
|
||||
|
||||
if (camExistsAndNeedsMoving)
|
||||
{
|
||||
xrRigGO.transform.position = camPose.position;
|
||||
xrRigGO.transform.rotation = camPose.rotation;
|
||||
}
|
||||
|
||||
TrackedPoseDriver trackedPoseDriver = xrCamera.gameObject.GetComponent<TrackedPoseDriver>();
|
||||
if (trackedPoseDriver == null)
|
||||
{
|
||||
trackedPoseDriver = Undo.AddComponent<TrackedPoseDriver>(xrCamera.gameObject);
|
||||
}
|
||||
trackedPoseDriver.SetPoseSource(TrackedPoseDriver.DeviceType.GenericXRDevice, TrackedPoseDriver.TrackedPose.Center);
|
||||
trackedPoseDriver.UseRelativeTransform = false;
|
||||
|
||||
var coh = xrRigGO.AddComponent<CameraOffset>();
|
||||
coh.cameraFloorOffsetObject = cameraOffsetGO;
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
coh.TrackingOriginMode = UnityEngine.XR.TrackingOriginModeFlags.Device;
|
||||
#else
|
||||
coh.trackingSpace = UnityEngine.XR.TrackingSpaceType.Stationary;
|
||||
#endif
|
||||
|
||||
gameObj = xrRigGO;
|
||||
Selection.activeGameObject = xrRigGO;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static Camera VerifyWeCanUpgrade()
|
||||
{
|
||||
Debug.Log("Determining if we can automatically upgrade this scene to use an XR Rig");
|
||||
|
||||
// rules are
|
||||
// only upgrade an empty scene with a directional light and a camera at the root node.
|
||||
var xrCameraList = Object.FindObjectsOfType<Camera>();
|
||||
Debug.Log("Checking number of cameras in the scene");
|
||||
if (xrCameraList.Length > 1)
|
||||
{
|
||||
// if the camera exists, and isn't at the root node. bail.
|
||||
Debug.LogError("You have more than one camera in your scene. We are unable to automatically convert your scene. Please see the documentation on how to upgrade your scene.");
|
||||
return null;
|
||||
}
|
||||
else if (xrCameraList.Length == 0)
|
||||
{
|
||||
Debug.LogError("You have no cameras in your scene. We are unable to automatically convert your scene. Please see the documentation on how to upgrade your scene.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
var xrCamera = xrCameraList.Length > 0 ? xrCameraList[0] : null;
|
||||
if (xrCamera != null)
|
||||
{
|
||||
Debug.Log("Checking Main Camera is at the root of the hierarchy");
|
||||
if (!(xrCamera.tag == kMainCamera && xrCamera.transform != null && xrCamera.transform.parent == null))
|
||||
{
|
||||
// if the camera exists, and isn't at the root node. bail.
|
||||
Debug.LogError("Your Main Camera is not at the root of your hierarchy. We are unable to automatically convert your scene. Please see the documentation on how to upgrade your scene.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Debug.Log("Checking camera components");
|
||||
List<Component> componentList = new List<Component>(xrCamera.gameObject.GetComponents(typeof(MonoBehaviour)));
|
||||
if (componentList.Count != 0)
|
||||
{
|
||||
|
||||
bool hdrp = false;
|
||||
bool urp = false;
|
||||
bool legacy = false;
|
||||
|
||||
#if HDRP_PRESENT
|
||||
hdrp = true;
|
||||
#endif
|
||||
#if URP_PRESENT
|
||||
urp = true;
|
||||
#endif
|
||||
legacy = !hdrp && !urp;
|
||||
|
||||
#pragma warning disable CS0219 // Variable is assigned but its value is never used
|
||||
bool hdrpCameraOk = false;
|
||||
bool urpCameraOk = false;
|
||||
bool hdrpComponentOk = true;
|
||||
bool urpComponentOk = true;
|
||||
#pragma warning restore CS0219 // Variable is assigned but its value is never used
|
||||
|
||||
// HDRP section.
|
||||
#if HDRP_PRESENT
|
||||
#if HDR_PRESENT_10_0
|
||||
hdrpCameraOk = xrCamera.IsHDCamera();
|
||||
hdrpComponentOk = (componentList.Count <= 2 && componentList.Find(x => x.GetType() == typeof(HDAdditionalCameraData)));
|
||||
#elif HDRP_PRESENT_10_1_OR_NEWER
|
||||
hdrpCameraOk = UnityEngine.Rendering.HighDefinition.ComponentUtility.IsHDCamera(xrCamera);
|
||||
hdrpComponentOk = (componentList.Count <= 2 && componentList.Find(x => x.GetType() == typeof(HDAdditionalCameraData)));
|
||||
#else
|
||||
hdrpCameraOk = true;
|
||||
hdrpComponentOk = (componentList.Count <= 2 && componentList.Find(x => x.GetType() == typeof(HDAdditionalCameraData)));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// URP Section
|
||||
#if URP_PRESENT
|
||||
#if URP_PRESENT_10_0
|
||||
urpCameraOk = xrCamera.IsUniversalCamera();
|
||||
urpComponentOk = (componentList.Count <= 2 && componentList.Find(x => x.GetType() == typeof(UniversalAdditionalCameraData)));
|
||||
#elif URP_PRESENT_10_1_OR_NEWER
|
||||
urpCameraOk = UnityEngine.Rendering.Universal.ComponentUtility.IsUniversalCamera(xrCamera);
|
||||
urpComponentOk = (componentList.Count <= 2 && componentList.Find(x => x.GetType() == typeof(UniversalAdditionalCameraData)));
|
||||
#else
|
||||
urpCameraOk = true;
|
||||
urpComponentOk = (componentList.Count <= 2 && componentList.Find(x => x.GetType() == typeof(UniversalAdditionalCameraData)));
|
||||
#endif
|
||||
#endif
|
||||
if (!((hdrp && hdrpCameraOk && hdrpComponentOk) || (urp && urpCameraOk && urpComponentOk) || (legacy)))
|
||||
{
|
||||
Debug.LogError("Your Main Camera has additional components that we do not recognize. We are unable to automatically convert your scene. Please see the documentation on how to upgrade your scene.");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
return xrCamera;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("GameObject/XR/Convert Main Camera To XR Rig", false, 10)]
|
||||
static void UpgradeToXRRig()
|
||||
{
|
||||
var xrCamera = VerifyWeCanUpgrade();
|
||||
if (xrCamera != null)
|
||||
{
|
||||
GameObject vrCameraRig;
|
||||
CreateSimpleXRRig(xrCamera, out vrCameraRig);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f594677a2340704797934efc5ba0678
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b9305ba4c18ed014ca21b12059ff734a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,658 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("UnityEditor.XR.LegacyInputHelpers.Tests")]
|
||||
|
||||
namespace UnityEditor.XR.LegacyInputHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// The SeedXRInputBindings class is used to populate the Input Asset with the cross platform bindings published by Unity for most XR Devices.
|
||||
/// </summary>
|
||||
public class SeedXRInputBindings
|
||||
{
|
||||
#region InputAxisDataAndConfig
|
||||
// Same as InputAxis.h
|
||||
internal class InputAxis
|
||||
{
|
||||
public string name = "";
|
||||
public string descriptiveName = "";
|
||||
public string descriptiveNegativeName = "";
|
||||
public string negativeButton = "";
|
||||
public string positiveButton = "";
|
||||
public string altNegativeButton = "";
|
||||
public string altPositiveButton = "";
|
||||
public float gravity = 0.0f;
|
||||
public float dead = 0.001f;
|
||||
public float sensitivity = 1.0f;
|
||||
public bool snap = false;
|
||||
public bool invert = false;
|
||||
public int type = 0;
|
||||
public int axis = 0;
|
||||
public int joyNum = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// NB: ALL AXIS VALUES WILL BE -1'd DURING PROCESSING, SO USE THE "REAL" AXIS VALUE
|
||||
//
|
||||
internal List<InputAxis> axisList = new List<InputAxis>
|
||||
{
|
||||
#region LeftHand
|
||||
//######################################################################################################################################
|
||||
// Left Hand
|
||||
//######################################################################################################################################
|
||||
// Axis Data
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Primary2DAxis_Vertical",
|
||||
descriptiveName = "Device joystick/touchpad horizontal motion",
|
||||
dead = 0.19f,
|
||||
axis = 2,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Primary2DAxis_Horizontal",
|
||||
descriptiveName = "Device joystick/touchpad horizontal motion",
|
||||
dead = 0.19f,
|
||||
axis = 1,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Secondary2DAxis_Vertical",
|
||||
descriptiveName = "Device joystick/touchpad horizontal motion.",
|
||||
dead = 0.19f,
|
||||
axis = 18,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Secondary2DAxis_Horizontal",
|
||||
descriptiveName = "Device joystick/touchpad horizontal motion",
|
||||
dead = 0.19f,
|
||||
axis = 17,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Trigger",
|
||||
descriptiveName = "Device trigger axis",
|
||||
axis = 9,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Grip",
|
||||
descriptiveName = "Device grip axis",
|
||||
axis = 11,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_IndexTouch",
|
||||
descriptiveName = "Device index finger proximity touch axis.",
|
||||
dead = 0.19f,
|
||||
axis = 13,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_ThumbTouch",
|
||||
descriptiveName = "Device thumb proximity touch axis",
|
||||
dead = 0.19f,
|
||||
axis = 15,
|
||||
type = 2,
|
||||
},
|
||||
// Button Data
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_PrimaryButton",
|
||||
descriptiveName = "Device primary button",
|
||||
positiveButton = "joystick button 2",
|
||||
gravity = 1000.0f,
|
||||
sensitivity = 1000.0f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_SecondaryButton",
|
||||
descriptiveName = "Device secondary button",
|
||||
positiveButton = "joystick button 3",
|
||||
gravity = 1000.0f,
|
||||
sensitivity = 1000.0f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_PrimaryTouch",
|
||||
descriptiveName = "Device primary touch",
|
||||
positiveButton = "joystick button 12",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_SecondaryTouch",
|
||||
descriptiveName = "Device secondary button",
|
||||
positiveButton = "joystick button 13",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_GripButton",
|
||||
descriptiveName = "Device grip button",
|
||||
positiveButton = "joystick button 4",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_TriggerButton",
|
||||
descriptiveName = "Device trigger button",
|
||||
positiveButton = "joystick button 14",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_MenuButton",
|
||||
descriptiveName = "Device menu button",
|
||||
positiveButton = "joystick button 6",
|
||||
gravity = 1000.0f,
|
||||
sensitivity = 1000.0f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Primary2DAxisClick",
|
||||
descriptiveName = "Device stick/touchpad click",
|
||||
positiveButton = "joystick button 8",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Primary2DAxisTouch",
|
||||
descriptiveName = "Device stick/touchpad touch",
|
||||
positiveButton = "joystick button 16",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Left_Thumbrest",
|
||||
descriptiveName = "Device thumbrest",
|
||||
positiveButton = "joystick button 18",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
#endregion
|
||||
#region RightHand
|
||||
//######################################################################################################################################
|
||||
// Right Hand
|
||||
//######################################################################################################################################
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Primary2DAxis_Vertical",
|
||||
descriptiveName = "Device joystick/touchpad horizontal motion",
|
||||
dead = 0.19f,
|
||||
axis = 5,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Primary2DAxis_Horizontal",
|
||||
descriptiveName = "Device joystick/touchpad horizontal motion",
|
||||
dead = 0.19f,
|
||||
axis = 4,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Secondary2DAxis_Vertical",
|
||||
descriptiveName = "Device joystick/touchpad horizontal motion.",
|
||||
dead = 0.19f,
|
||||
axis = 20,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Secondary2DAxis_Horizontal",
|
||||
descriptiveName = "Device joystick/touchpad horizontal motion",
|
||||
dead = 0.19f,
|
||||
axis = 19,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Trigger",
|
||||
descriptiveName = "Device trigger axis",
|
||||
axis = 10,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Grip",
|
||||
descriptiveName = "Device grip axis",
|
||||
axis = 12,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_IndexTouch",
|
||||
descriptiveName = "Device index finger proximity touch axis.",
|
||||
dead = 0.19f,
|
||||
axis = 14,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_ThumbTouch",
|
||||
descriptiveName = "Device thumb proximity touch axis",
|
||||
dead = 0.19f,
|
||||
axis = 16,
|
||||
type = 2,
|
||||
},
|
||||
// Button Data
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_PrimaryButton",
|
||||
descriptiveName = "Device primary button",
|
||||
positiveButton = "joystick button 0",
|
||||
gravity = 1000.0f,
|
||||
sensitivity = 1000.0f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_SecondaryButton",
|
||||
descriptiveName = "Device secondary button",
|
||||
positiveButton = "joystick button 1",
|
||||
gravity = 1000.0f,
|
||||
sensitivity = 1000.0f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_PrimaryTouch",
|
||||
descriptiveName = "Device primary touch",
|
||||
positiveButton = "joystick button 10",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_SecondaryTouch",
|
||||
descriptiveName = "Device secondary button",
|
||||
positiveButton = "joystick button 11",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_GripButton",
|
||||
descriptiveName = "Device grip button",
|
||||
positiveButton = "joystick button 5",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_TriggerButton",
|
||||
descriptiveName = "Device trigger button",
|
||||
positiveButton = "joystick button 15",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_MenuButton",
|
||||
descriptiveName = "Device menu button",
|
||||
positiveButton = "joystick button 7",
|
||||
gravity = 1000.0f,
|
||||
sensitivity = 1000.0f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Primary2DAxisClick",
|
||||
descriptiveName = "Device stick/touchpad click",
|
||||
positiveButton = "joystick button 9",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Primary2DAxisTouch",
|
||||
descriptiveName = "Device stick/touchpad touch",
|
||||
positiveButton = "joystick button 17",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Right_Thumbrest",
|
||||
descriptiveName = "Device thumbrest",
|
||||
positiveButton = "joystick button 19",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
#endregion
|
||||
#region UGuiRequired
|
||||
//######################################################################################################################################
|
||||
// UGui Required
|
||||
//######################################################################################################################################
|
||||
new InputAxis()
|
||||
{
|
||||
name = "Submit",
|
||||
descriptiveName = "Submit",
|
||||
positiveButton = "joystick button 0",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "Cancel",
|
||||
descriptiveName = "Cancel",
|
||||
positiveButton = "joystick button 1",
|
||||
gravity = 0.0f,
|
||||
dead = 0.0f,
|
||||
sensitivity = 0.1f,
|
||||
type = 0,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "Horizontal",
|
||||
descriptiveName = "Horizontal",
|
||||
dead = 0.19f,
|
||||
axis = 4,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "Vertical",
|
||||
descriptiveName = "Vertical",
|
||||
dead = 0.19f,
|
||||
axis = 5,
|
||||
type = 2,
|
||||
},
|
||||
#endregion
|
||||
//######################################################################################################################################
|
||||
// Combined Trigger
|
||||
//######################################################################################################################################
|
||||
#region Combined
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_Combined_Trigger",
|
||||
descriptiveName = "Combined Trigger",
|
||||
dead = 0.19f,
|
||||
axis = 3,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_DPad_Vertical",
|
||||
descriptiveName = "Device directional pad. These values are replicated l/r",
|
||||
axis = 7,
|
||||
type = 2,
|
||||
},
|
||||
new InputAxis()
|
||||
{
|
||||
name = "XRI_DPad_Horizontal",
|
||||
descriptiveName = "Device directional pad. These values are replicated l/r",
|
||||
axis = 6,
|
||||
type = 2,
|
||||
},
|
||||
#endregion
|
||||
};
|
||||
|
||||
internal struct BindingData
|
||||
{
|
||||
public int newDataIndex;
|
||||
public int inputManagerIndex;
|
||||
public bool exists;
|
||||
}
|
||||
#endregion
|
||||
|
||||
///<summary>
|
||||
/// Menu option which will allow users to seed the automatic bindings for the legacy input system.
|
||||
///</summary>
|
||||
[MenuItem("Assets/Seed XR Input Bindings")]
|
||||
static public void GenerateXRBindingsMenuItem()
|
||||
{
|
||||
SeedXRInputBindings sxrib = new SeedXRInputBindings();
|
||||
sxrib.GenerateXRBindings();
|
||||
SettingsService.OpenProjectSettings("Project/Input");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main entrypoint for generating the XR Bindings and adding them to the Input Asset. The Custom uGUI editor calls this function when the user wishes to
|
||||
/// seed the Input Asset with XR bindings.
|
||||
/// </summary>
|
||||
public void GenerateXRBindings()
|
||||
{
|
||||
// seed map of axis data so we can whitewash against existing.
|
||||
Dictionary<string, BindingData> axisMap = new Dictionary<string, BindingData>();
|
||||
for (int i = 0; i < axisList.Count; ++i)
|
||||
{
|
||||
axisMap.Add(axisList[i].name, new BindingData() { newDataIndex = i, exists = false, inputManagerIndex = -1 });
|
||||
if (axisList[i].axis > 0)
|
||||
{
|
||||
axisList[i].axis--;
|
||||
}
|
||||
}
|
||||
|
||||
// load the input asset
|
||||
var inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
|
||||
if (inputManagerAsset != null)
|
||||
{
|
||||
var serializedObject = new SerializedObject(inputManagerAsset);
|
||||
var inputManagerCurrentData = serializedObject.FindProperty("m_Axes");
|
||||
|
||||
if (inputManagerCurrentData != null)
|
||||
{
|
||||
List<InputAxis> currentInputData = new List<InputAxis>();
|
||||
LoadExistingDataAndCheckAgainstNewData(inputManagerCurrentData, ref axisMap, ref currentInputData);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
ApplyDataToInputManager(currentInputData, axisList, axisMap, ref inputManagerCurrentData);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region InternalProcessingCode
|
||||
|
||||
internal void ApplyDataToInputManager(List<InputAxis> inputManagerData, List<InputAxis> newData, Dictionary<string, BindingData> newDataMap, ref SerializedProperty arrayRoot)
|
||||
{
|
||||
// likely will be larger than we need, but that's ok. it'll be big enough for all the data which is worst case
|
||||
arrayRoot.arraySize = inputManagerData.Count + newData.Count;
|
||||
|
||||
int arrayIndex = inputManagerData.Count;
|
||||
// write everything that doesn't clash from our new data
|
||||
for (int i = 0; i < newData.Count; ++i)
|
||||
{
|
||||
BindingData bindingData;
|
||||
if (newDataMap.TryGetValue(newData[i].name, out bindingData))
|
||||
{
|
||||
if (bindingData.exists == true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
var axisEntry = arrayRoot.GetArrayElementAtIndex(arrayIndex);
|
||||
WriteDataToInputAxis(newData[i], ref axisEntry);
|
||||
arrayIndex++;
|
||||
}
|
||||
arrayRoot.arraySize = arrayIndex;
|
||||
}
|
||||
|
||||
internal void WriteDataToInputAxis(InputAxis sourceData, ref SerializedProperty serializedProperty)
|
||||
{
|
||||
var iteratorProperty = serializedProperty.Copy();
|
||||
iteratorProperty.Next(true);
|
||||
do
|
||||
{
|
||||
switch (iteratorProperty.name)
|
||||
{
|
||||
case "m_Name":
|
||||
iteratorProperty.stringValue = sourceData.name;
|
||||
break;
|
||||
case "descriptiveName":
|
||||
iteratorProperty.stringValue = sourceData.descriptiveName;
|
||||
break;
|
||||
case "descriptiveNegativeName":
|
||||
iteratorProperty.stringValue = sourceData.descriptiveNegativeName;
|
||||
break;
|
||||
case "negativeButton":
|
||||
iteratorProperty.stringValue = sourceData.negativeButton;
|
||||
break;
|
||||
case "positiveButton":
|
||||
iteratorProperty.stringValue = sourceData.positiveButton;
|
||||
break;
|
||||
case "altNegativeButton":
|
||||
iteratorProperty.stringValue = sourceData.altNegativeButton;
|
||||
break;
|
||||
case "altPositiveButton":
|
||||
iteratorProperty.stringValue = sourceData.altPositiveButton;
|
||||
break;
|
||||
case "gravity":
|
||||
iteratorProperty.floatValue = sourceData.gravity;
|
||||
break;
|
||||
case "dead":
|
||||
iteratorProperty.floatValue = sourceData.dead;
|
||||
break;
|
||||
case "sensitivity":
|
||||
iteratorProperty.floatValue = sourceData.sensitivity;
|
||||
break;
|
||||
case "snap":
|
||||
iteratorProperty.boolValue = sourceData.snap;
|
||||
break;
|
||||
case "invert":
|
||||
iteratorProperty.boolValue = sourceData.invert;
|
||||
break;
|
||||
case "type":
|
||||
iteratorProperty.intValue = sourceData.type;
|
||||
break;
|
||||
case "axis":
|
||||
iteratorProperty.intValue = sourceData.axis;
|
||||
break;
|
||||
case "joyNum":
|
||||
iteratorProperty.intValue = sourceData.joyNum;
|
||||
break;
|
||||
|
||||
}
|
||||
} while (iteratorProperty.Next(false));
|
||||
}
|
||||
|
||||
internal void LoadExistingDataAndCheckAgainstNewData(SerializedProperty arrayRoot, ref Dictionary<string, BindingData> newDataMap, ref List<InputAxis> existingData)
|
||||
{
|
||||
existingData.Clear();
|
||||
for (int i = 0; i < arrayRoot.arraySize; ++i)
|
||||
{
|
||||
InputAxis readData = new InputAxis();
|
||||
|
||||
var axisEntry = arrayRoot.GetArrayElementAtIndex(i);
|
||||
var iteratorProperty = axisEntry.Copy();
|
||||
iteratorProperty.Next(true);
|
||||
do
|
||||
{
|
||||
switch (iteratorProperty.name)
|
||||
{
|
||||
case "m_Name":
|
||||
readData.name = iteratorProperty.stringValue;
|
||||
BindingData bindingData;
|
||||
if (newDataMap.TryGetValue(readData.name, out bindingData))
|
||||
{
|
||||
// using TryGetElement returns a copy, not very useful.
|
||||
bindingData.exists = true;
|
||||
bindingData.inputManagerIndex = i;
|
||||
newDataMap[readData.name] = bindingData;
|
||||
}
|
||||
break;
|
||||
case "descriptiveName":
|
||||
readData.descriptiveName = iteratorProperty.stringValue;
|
||||
break;
|
||||
case "descriptiveNegativeName":
|
||||
readData.descriptiveNegativeName = iteratorProperty.stringValue;
|
||||
break;
|
||||
case "negativeButton":
|
||||
readData.negativeButton = iteratorProperty.stringValue;
|
||||
break;
|
||||
case "positiveButton":
|
||||
readData.positiveButton = iteratorProperty.stringValue;
|
||||
break;
|
||||
case "altNegativeButton":
|
||||
readData.altNegativeButton = iteratorProperty.stringValue;
|
||||
break;
|
||||
case "altPositiveButton":
|
||||
readData.altPositiveButton = iteratorProperty.stringValue;
|
||||
break;
|
||||
case "gravity":
|
||||
readData.gravity = iteratorProperty.floatValue;
|
||||
break;
|
||||
case "dead":
|
||||
readData.dead = iteratorProperty.floatValue;
|
||||
break;
|
||||
case "sensitivity":
|
||||
readData.sensitivity = iteratorProperty.floatValue;
|
||||
break;
|
||||
case "snap":
|
||||
readData.snap = iteratorProperty.boolValue;
|
||||
break;
|
||||
case "invert":
|
||||
readData.invert = iteratorProperty.boolValue;
|
||||
break;
|
||||
case "type":
|
||||
readData.type = iteratorProperty.intValue;
|
||||
break;
|
||||
case "axis":
|
||||
readData.axis = iteratorProperty.intValue;
|
||||
break;
|
||||
case "joyNum":
|
||||
readData.joyNum = iteratorProperty.intValue;
|
||||
break;
|
||||
}
|
||||
} while (iteratorProperty.Next(false));
|
||||
existingData.Add(readData);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ebb01c3a5ac7564d80fe780a7058df0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fe5c30c1d5f39024cb890d87f6eea1a6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ab51dfc975464354d9f0d2205097fa04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,98 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.SpatialTracking
|
||||
{
|
||||
// TODO: If this Editor class is ever made public, fix the namespace to be UnityEditor.SpatialTracking, not UnityEngine.SpatialTracking
|
||||
[CustomEditor(typeof(TrackedPoseDriver))]
|
||||
internal class TrackedPoseDriverEditor : Editor
|
||||
{
|
||||
static class Styles
|
||||
{
|
||||
public static GUIContent deviceLabel = EditorGUIUtility.TrTextContent("Device", "The Device to read tracking data from");
|
||||
public static GUIContent poseLabel = EditorGUIUtility.TrTextContent("Pose Source", "The end point on the device to read tracking data from");
|
||||
public static GUIContent trackingLabel = EditorGUIUtility.TrTextContent("Tracking Type", "Whether Rotation or Position, or Both are applied from the source pose");
|
||||
public static GUIContent updateLabel = EditorGUIUtility.TrTextContent("Update Type", "Whether the Tracked Pose Driver updates in update, and/or just before rendering");
|
||||
public static GUIContent relativeLabel = EditorGUIUtility.TrTextContent("Use Relative Transform", "When this is set, the Tracked Pose Driver will use the original position of the object as a reference. This option will be deprecated in future releases");
|
||||
public static GUIContent poseProviderLabel = EditorGUIUtility.TrTextContent("Use Pose Provider", "[Optional] when a PoseProvider object is attached here, the pose provider will be used as the data source, not the Device/Pose settings on the Tracked Pose Driver");
|
||||
public static readonly string poseProviderWarning = "This Tracked Pose Driver is using an external component as its Pose Source.";
|
||||
public static readonly string devicePropWarning = "The selected Pose Source is not valid, please pick a different pose";
|
||||
public static readonly string cameraWarning = "The Tracked Pose Driver is attached to a Camera, but is not tracking the Center Eye / HMD Reference. This may cause tracking problems if this Camera is intended to track the headset.";
|
||||
}
|
||||
|
||||
SerializedProperty m_DeviceProp = null;
|
||||
SerializedProperty m_PoseLabelProp = null;
|
||||
SerializedProperty m_TrackingTypeProp = null;
|
||||
SerializedProperty m_UpdateTypeProp = null;
|
||||
SerializedProperty m_UseRelativeTransformProp = null;
|
||||
SerializedProperty m_PoseProviderProp = null;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
m_DeviceProp = this.serializedObject.FindProperty("m_Device");
|
||||
m_PoseLabelProp = this.serializedObject.FindProperty("m_PoseSource");
|
||||
m_TrackingTypeProp = this.serializedObject.FindProperty("m_TrackingType");
|
||||
m_UpdateTypeProp = this.serializedObject.FindProperty("m_UpdateType");
|
||||
m_UseRelativeTransformProp = this.serializedObject.FindProperty("m_UseRelativeTransform");
|
||||
m_PoseProviderProp = this.serializedObject.FindProperty("m_PoseProviderComponent");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
TrackedPoseDriver tpd = target as TrackedPoseDriver;
|
||||
serializedObject.Update();
|
||||
|
||||
if (m_PoseProviderProp.objectReferenceValue == null)
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_DeviceProp, Styles.deviceLabel);
|
||||
|
||||
int selectedIndex = -1;
|
||||
for (int i = 0; i < TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses.Count; ++i)
|
||||
{
|
||||
if ((int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[i] == m_PoseLabelProp.enumValueIndex)
|
||||
{
|
||||
selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Rect rect = EditorGUILayout.GetControlRect();
|
||||
EditorGUI.LabelField(rect, Styles.poseLabel);
|
||||
rect.xMin += EditorGUIUtility.labelWidth;
|
||||
|
||||
if (selectedIndex != -1)
|
||||
{
|
||||
int index = EditorGUI.Popup(rect, selectedIndex, TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].PoseNames.ToArray());
|
||||
m_PoseLabelProp.enumValueIndex = (int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[index];
|
||||
if(tpd &&
|
||||
(m_DeviceProp.enumValueIndex == 0 &&
|
||||
(m_PoseLabelProp.enumValueIndex != (int)(TrackedPoseDriver.TrackedPose.Center)) &&
|
||||
(m_PoseLabelProp.enumValueIndex != (int)TrackedPoseDriver.TrackedPose.ColorCamera)))
|
||||
{
|
||||
Camera camera = tpd.GetComponent<Camera>();
|
||||
if (camera != null)
|
||||
{
|
||||
EditorGUILayout.HelpBox(Styles.cameraWarning, MessageType.Warning, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = EditorGUI.Popup(rect, 0, TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].PoseNames.ToArray());
|
||||
m_PoseLabelProp.enumValueIndex = (int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[index];
|
||||
EditorGUILayout.HelpBox(Styles.devicePropWarning, MessageType.Warning, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox(Styles.poseProviderWarning, MessageType.Info, true);
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(m_TrackingTypeProp, Styles.trackingLabel);
|
||||
EditorGUILayout.PropertyField(m_UpdateTypeProp, Styles.updateLabel);
|
||||
EditorGUILayout.PropertyField(m_UseRelativeTransformProp, Styles.relativeLabel);
|
||||
|
||||
EditorGUILayout.PropertyField(m_PoseProviderProp, Styles.poseProviderLabel);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89c097ec5a9e1d0409a12d54380028f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "UnityEditor.SpatialTracking",
|
||||
"references": [
|
||||
"UnityEngine.SpatialTracking"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.xr.management",
|
||||
"expression": "1.0.0",
|
||||
"define": "XR_MANAGEMENT"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b13a1d1dfb13f1b489a0ff5612f36f29
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue