using System; using System.Collections.Generic; using System.Linq; using Unity.XR.CoreUtils; using UnityEngine; using UnityEngine.Scripting.APIUpdating; using UnityEngine.XR; using UnityEngine.XR.Interaction.Toolkit; namespace UnityEditor.XR.Interaction.Toolkit { /// /// Custom editor for the deprecated . /// [Obsolete("XRRigEditor has been deprecated. Use XROriginEditor instead.", true)] [CustomEditor(typeof(XRRig), true), CanEditMultipleObjects] [MovedFrom("UnityEngine.XR.Interaction.Toolkit")] public class XRRigEditor : BaseInteractionEditor { /// of the backing . protected SerializedProperty m_RigBaseGameObject; /// of the backing . protected SerializedProperty m_CameraFloorOffsetObject; /// of the backing . protected SerializedProperty m_CameraGameObject; /// of the backing . protected SerializedProperty m_Camera; /// m_TrackingOriginMode has been deprecated. Use m_RequestedTrackingOriginMode instead.. [Obsolete("m_TrackingOriginMode has been deprecated. Use m_RequestedTrackingOriginMode instead.", true)] protected SerializedProperty m_TrackingOriginMode; /// of the backing . protected SerializedProperty m_RequestedTrackingOriginMode; /// of the backing . protected SerializedProperty m_CameraYOffset; List m_Rigs; readonly GUIContent[] m_MixedValuesOptions = { Contents.mixedValues }; /// /// Contents of GUI elements used by this editor. /// protected static class Contents { /// for . public static readonly GUIContent rig = EditorGUIUtility.TrTextContent("Rig Base GameObject", "The \"Rig\" GameObject is used to refer to the base of the XR Origin, by default it is this GameObject. This is the GameObject that will be manipulated via locomotion."); /// for . public static readonly GUIContent cameraFloorOffsetObject = EditorGUIUtility.TrTextContent("Camera Floor Offset Object", "The GameObject to move to desired height off the floor (defaults to this object if none provided)."); /// for . public static readonly GUIContent cameraGameObject = EditorGUIUtility.TrTextContent("Camera GameObject", "The GameObject that contains the camera, this is usually the \"Head\" of XR Origins."); /// for . public static readonly GUIContent camera = EditorGUIUtility.TrTextContent("Camera", "The Camera, this is usually the \"Head\" of XR Origins."); /// for . public static readonly GUIContent trackingOriginMode = EditorGUIUtility.TrTextContent("Tracking Origin Mode", "The type of tracking origin to use for this Rig. Tracking origins identify where (0, 0, 0) is in the world of tracking."); /// for . public static readonly GUIContent currentTrackingOriginMode = EditorGUIUtility.TrTextContent("Current Tracking Origin Mode", "The Tracking Origin Mode that this Rig is in."); /// for . public static readonly GUIContent cameraYOffset = EditorGUIUtility.TrTextContent("Camera Y Offset", "Camera height to be used when in \"Device\" Tracking Origin Mode to define the height of the user from the floor."); /// to indicate mixed values when multi-object editing. public static readonly GUIContent mixedValues = EditorGUIUtility.TrTextContent("\u2014", "Mixed Values"); } /// /// This function is called when the object becomes enabled and active. /// /// protected virtual void OnEnable() { m_RigBaseGameObject = serializedObject.FindProperty("m_OriginBaseGameObject"); m_CameraFloorOffsetObject = serializedObject.FindProperty("m_CameraFloorOffsetObject"); m_CameraGameObject = serializedObject.FindProperty("m_CameraGameObject"); m_Camera = serializedObject.FindProperty("m_Camera"); m_RequestedTrackingOriginMode = serializedObject.FindProperty("m_RequestedTrackingOriginMode"); m_CameraYOffset = serializedObject.FindProperty("m_CameraYOffset"); m_Rigs = targets.Cast().ToList(); } /// protected override List GetDerivedSerializedPropertyNames() { var propertyNames = base.GetDerivedSerializedPropertyNames(); // Ignore these fields since they are deprecated and only kept around for data migration propertyNames.Add("m_TrackingSpace"); return propertyNames; } /// /// /// /// protected override void DrawInspector() { DrawBeforeProperties(); DrawProperties(); DrawDerivedProperties(); } /// /// This method is automatically called by to /// draw the section of the custom inspector before . /// By default, this draws the read-only Script property. /// protected virtual void DrawBeforeProperties() { DrawScript(); } /// /// This method is automatically called by to /// draw the property fields. Override this method to customize the /// properties shown in the Inspector. This is typically the method overridden /// when a derived behavior adds additional serialized properties /// that should be displayed in the Inspector. /// protected virtual void DrawProperties() { EditorGUILayout.PropertyField(m_RigBaseGameObject, Contents.rig); EditorGUILayout.PropertyField(m_CameraFloorOffsetObject, Contents.cameraFloorOffsetObject); if (m_Camera.objectReferenceValue != null || m_CameraGameObject.objectReferenceValue == null) EditorGUILayout.PropertyField(m_Camera, Contents.camera); else EditorGUILayout.PropertyField(m_CameraGameObject, Contents.cameraGameObject); EditorGUILayout.PropertyField(m_RequestedTrackingOriginMode, Contents.trackingOriginMode); var showCameraYOffset = m_RequestedTrackingOriginMode.intValue == (int)XROrigin.TrackingOriginMode.NotSpecified || m_RequestedTrackingOriginMode.intValue == (int)XROrigin.TrackingOriginMode.Device || m_RequestedTrackingOriginMode.hasMultipleDifferentValues; if (showCameraYOffset) { #if ENABLE_VR || UNITY_GAMECORE // The property should be enabled when not playing since the default for the XR device // may be Device, so the property should be editable to define the offset. // When playing, disable the property to convey that it isn't having an effect, // which is when the current mode is Floor. var currentTrackingOriginMode = ((XRRig)target).CurrentTrackingOriginMode; var allCurrentlyFloor = (m_Rigs.Count == 1 && currentTrackingOriginMode == TrackingOriginModeFlags.Floor) || m_Rigs.All(rig => rig.CurrentTrackingOriginMode == TrackingOriginModeFlags.Floor); var disabled = Application.isPlaying && !m_RequestedTrackingOriginMode.hasMultipleDifferentValues && m_RequestedTrackingOriginMode.intValue == (int)XROrigin.TrackingOriginMode.NotSpecified && allCurrentlyFloor; #else const bool disabled = false; #endif using (new EditorGUI.IndentLevelScope()) using (new EditorGUI.DisabledScope(disabled)) { EditorGUILayout.PropertyField(m_CameraYOffset, Contents.cameraYOffset); } } DrawCurrentTrackingOriginMode(); } /// /// Draw the current Tracking Origin Mode while the application is playing. /// /// protected void DrawCurrentTrackingOriginMode() { #if ENABLE_VR || UNITY_GAMECORE if (!Application.isPlaying) return; using (new EditorGUI.DisabledScope(true)) { var currentTrackingOriginMode = ((XRRig)target).CurrentTrackingOriginMode; if (m_Rigs.Count == 1 || m_Rigs.All(rig => rig.CurrentTrackingOriginMode == currentTrackingOriginMode)) EditorGUILayout.EnumPopup(Contents.currentTrackingOriginMode, currentTrackingOriginMode); else EditorGUILayout.Popup(Contents.currentTrackingOriginMode, 0, m_MixedValuesOptions); } #endif } } }