#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateARAnnotationInteractable(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(); CreateAndPlaceGameObject("AR Annotation Interactable", menuCommand.GetContextTransform(), typeof(ARRotationInteractable)); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateARGestureInteractor(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(); var originGO = CreateAndPlaceGameObject("AR Session Origin", menuCommand.GetContextTransform(), typeof(ARSessionOrigin)); var cameraGO = CreateAndPlaceGameObject("AR Camera", originGO.transform, typeof(Camera), typeof(TrackedPoseDriver), typeof(ARCameraManager), typeof(ARCameraBackground), typeof(ARGestureInteractor)); var camera = cameraGO.GetComponent <Camera>(); Undo.RecordObject(camera, "Configure AR Camera"); camera.clearFlags = CameraClearFlags.Color; camera.backgroundColor = Color.black; camera.nearClipPlane = 0.1f; camera.farClipPlane = 20f; var origin = originGO.GetComponent <ARSessionOrigin>(); Undo.RecordObject(origin, "Configure AR Session Origin"); origin.camera = camera; var trackedPoseDriver = cameraGO.GetComponent <TrackedPoseDriver>(); Undo.RecordObject(trackedPoseDriver, "Configure Tracked Pose Driver"); trackedPoseDriver.SetPoseSource(TrackedPoseDriver.DeviceType.GenericXRDevice, TrackedPoseDriver.TrackedPose.ColorCamera); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateDirectInteractorDeviceBased(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(); CreateDirectInteractor(menuCommand.GetContextTransform(), InputType.DeviceBased); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateTeleportationArea(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(); CreateAndPlacePrimitive("Teleportation Area", menuCommand.GetContextTransform(), PrimitiveType.Plane, typeof(TeleportationArea)); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateXRUICanvas(MenuCommand menuCommand) #pragma warning restore IDE0051 { var parentOfNewGameObject = menuCommand.GetContextTransform(); var editingPrefabStage = (StageUtility.GetCurrentStageHandle() != StageUtility.GetMainStageHandle()); var canvasGO = CreateAndPlaceGameObject("Canvas", parentOfNewGameObject, typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster), typeof(TrackedDeviceGraphicRaycaster)); // Either inherit the layer of the parent object, or use the same default that GameObject/UI/Canvas uses. if (parentOfNewGameObject == null) { Undo.RegisterCompleteObjectUndo(canvasGO, "Change Layer"); canvasGO.layer = LayerMask.NameToLayer(k_UILayerName); } var canvas = canvasGO.GetComponent <Canvas>(); Undo.RecordObject(canvas, "Configure Canvas"); canvas.renderMode = RenderMode.WorldSpace; if (!editingPrefabStage) { canvas.worldCamera = Camera.main; } else { Debug.LogWarning("You have just added an XR UI Canvas to a prefab." + $" To function properly with an {nameof(XRRayInteractor)}, you must also set the Canvas component's worldCamera field in your scene.", canvasGO); } // Ensure there is at least one EventSystem setup properly var inputModule = Object.FindObjectOfType <XRUIInputModule>(); if (inputModule == null) { if (!editingPrefabStage) { CreateXRUIEventSystem(menuCommand); } else { Debug.LogWarning("You have just added an XR UI Canvas to a prefab." + $" To function properly with an {nameof(XRRayInteractor)}, you must also add an XR UI EventSystem to your scene.", canvasGO); } } // May need to set this again since creating the XR UI EventSystem would have overwritten this Undo.SetCurrentGroupName("Create " + canvasGO.name); Selection.activeGameObject = canvasGO; }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateSocketInteractor(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(); var socketInteractableGO = CreateAndPlaceGameObject("Socket Interactor", menuCommand.GetContextTransform(), typeof(SphereCollider), typeof(XRSocketInteractor)); var sphereCollider = socketInteractableGO.GetComponent <SphereCollider>(); Undo.RecordObject(sphereCollider, "Configure Sphere Collider"); sphereCollider.isTrigger = true; sphereCollider.radius = GetScaledRadius(sphereCollider, 0.1f); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateGrabInteractable(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(); var grabInteractableGO = CreateAndPlaceGameObject("Grab Interactable", menuCommand.GetContextTransform(), typeof(XRGrabInteractable), typeof(SphereCollider)); var sphereCollider = grabInteractableGO.GetComponent <SphereCollider>(); Undo.RecordObject(sphereCollider, "Configure Sphere Collider"); sphereCollider.isTrigger = false; sphereCollider.radius = 0.1f; }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateTeleportationAnchor(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(); var anchorGO = CreateAndPlacePrimitive("Teleportation Anchor", menuCommand.GetContextTransform(), PrimitiveType.Plane, typeof(TeleportationAnchor)); var destinationGO = ObjectFactory.CreateGameObject("Anchor"); Place(destinationGO, anchorGO.transform); var teleportationAnchor = anchorGO.GetComponent <TeleportationAnchor>(); Undo.RecordObject(teleportationAnchor, "Configure Teleportation Anchor"); teleportationAnchor.teleportAnchorTransform = destinationGO.transform; }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateGrabInteractable(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(); var grabInteractableGO = CreateAndPlacePrimitive("Grab Interactable", menuCommand.GetContextTransform(), PrimitiveType.Cube, typeof(XRGrabInteractable)); var transform = grabInteractableGO.transform; Undo.RecordObject(transform, "Configure Transform"); var localScale = InverseTransformScale(transform, new Vector3(0.1f, 0.1f, 0.1f)); transform.localScale = Abs(localScale); var boxCollider = grabInteractableGO.GetComponent <BoxCollider>(); Undo.RecordObject(boxCollider, "Configure Box Collider"); // BoxCollider does not support a negative effective size, // so ensure the size accounts for any negative scaling. boxCollider.size = Vector3.Scale(boxCollider.size, Sign(localScale)); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateXRUIEventSystem(MenuCommand menuCommand) #pragma warning restore IDE0051 { var currentStage = StageUtility.GetCurrentStageHandle(); // Ensure there is at least one EventSystem setup properly var inputModule = currentStage.FindComponentOfType <XRUIInputModule>(); if (inputModule == null) { var eventSystem = currentStage.FindComponentOfType <EventSystem>(); GameObject eventSystemGO; if (eventSystem == null) { eventSystemGO = CreateAndPlaceGameObject("EventSystem", menuCommand.GetContextTransform(), typeof(EventSystem), typeof(XRUIInputModule)); } else { eventSystemGO = eventSystem.gameObject; // Remove the Standalone Input Module if already implemented, since it will block the XRUIInputModule var standaloneInputModule = eventSystemGO.GetComponent <StandaloneInputModule>(); if (standaloneInputModule != null) { Undo.DestroyObjectImmediate(standaloneInputModule); } Undo.AddComponent <XRUIInputModule>(eventSystemGO); } inputModule = eventSystemGO.GetComponent <XRUIInputModule>(); } Selection.activeGameObject = inputModule.gameObject; }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateLocomotionSystemDeviceBased(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateLocomotionSystem(menuCommand.GetContextTransform(), InputType.DeviceBased); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateXRRigDeviceBased(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateXRRigWithHandControllers(menuCommand.GetContextTransform(), InputType.DeviceBased); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateInteractionManager(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateInteractionManager(menuCommand.GetContextTransform()); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateStationaryXRRigDeviceBased(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateStationaryXRRig(menuCommand.GetContextTransform(), InputType.DeviceBased); }
#pragma warning disable IDE0051 // Remove unused private members -- Editor Menu Item static void CreateRoomScaleXRRigActionBased(MenuCommand menuCommand) #pragma warning restore IDE0051 { CreateRoomScaleXRRig(menuCommand.GetContextTransform(), InputType.ActionBased); }