Skip to content

The Basics

simpleOmnia edited this page Nov 30, 2023 · 7 revisions

Overview

sXR is designed to be as intuitive as possible. All commands are called by typing "sxr." + a keyword for whatever it is you're trying to do. For example, if I wanted to change an object's visibility: ideFill

Any modern IDE will find commands with the keyword and display the code's docstring (which explains what the function does). In the above example, starting to type "sxr.visibility" brought up the command "ObjectVisibility" and the description, "Sets the object's visibility through (de)activating the MeshRenderer". The docstring also tells you the function can take in (GameObject gameObj, bool visibile) or (string objName, bool visible). If using the "string objName" option, sXR will search for any object with the provided name. The "GameObject gameObj" allows you to pass in the Unity game object (found with "sxr.GetObject") which can save some computational power by avoiding the object search. The second parameter "bool visible" will determine whether the specified object should be visible.

Each of sxr's functions has an associated docstring. A list of all functions with a brief description is also available on the project's ReadMe.

Note: Most commands can be completed with a string version of a parameter. For example, using "sxr.PlaySound("mySound")" would search through all 'Resources' folders for a file named "mySound.xxx". For files, the file type extension is not included in the input string (i.e. the string should be "mySound" and not "mySound.mp3"). GameObjects, timers, sounds, images, and shaders can all be accessed by name in their various functions.

Using SimpleXR

To use sXR's functions, you replace the scene's "Main Camera" with the sxr_prefab by right-clicking in the hierarchy to add a GameObject and clicking on simpleXR->sxr_prefab. It requires resources to be loaded into the asset folder. You may need to click to add the prefab twice if the assets didn't automatically load in upon installation.

The prefab is composed of four main components.

Experimenter Screen

exp screen The experimenter's screen starts with the screen shown above. Here the researcher can specify the subject number and which Phase/Block/Trial to start on. After the start button is pressed, the "StartScreen" is hidden and the five "DisplayText" boxes are displayed on the experimenter's screen (but not the participants!). By default, Textbox1 contains the current "[Phase]-Block: trial(step)", Textbox2 contains the player's position, and Textbox3 displays the time remaining in the trial timer. Textbox4 and 5 can be changed with the "sxr.ChangeExperimenterTextbox" command and specifying the Textbox number. It is possible to override Textbox 1-3 by using the "sxr.UseDefaultExperimenterTextboxes" function.

sXR Backend

back SimpleXR relies (perhaps too heavily) on singletons for most of its functionality. Singletons are simply classes that can only have one active instance, with subsequent objects containing the same singleton being deleted. For the most part, users will not need to access sXR's backend, but some more advanced users may find some of the public fields advantageous for debugging.

NonInteractableUI

UI assembly The NonInteractableUI contains a secondary camera to display over the VR camera. The "MainCanvas" contains empty image/textboxes to display UI elements with sxr.DisplayImage() and sxr.DisplayText(). The main GameObject also has the UI_Handler singleton attached which handles assigning UI components and interacting with the interactive UI component.

XR Rig

vr assembly The XR_Rig contains all the required components to facilitate XR interactions. The model is similar to the "Starter Assets" demo scene of XR Interaction Toolkit. The "Locomotion System" is deactivated by default and should be enabled if trying to perform Unity's XR Interactions. This includes things like climbing objects, moving with the controller, and teleporting with the controller. This setup also allows for customized haptics when interacting with an XR Ray Interactor (such as vibrating if the laser hovers over certain objects).

The XR_Rig also contains the VR camera and representations of the left and right controllers. The model for controllers can be changed, but the naming scheme should remain the same or certain functions (like "sxr.MakeObjectGrabbable()") will not work properly. In other words, you can replace the mesh for "RightControllerCapsule", but make sure the GameObject name is the same and there is an attached collider. Each controller also has two associated lasers. One to interact with the environment (e.g. LaserRightEnvironment) and one to interact with the UI (e.g. LaserRightUI). By default the visualizations for these lasers and the controller capsules is enabled. To turn off the visualization, use sxr.ControllerVisual().

The "Main Camera" is the VR camera and will automatically move with the headset. The camera has an attached "InteractiveUI" canvas which contains UI components that can be interacted with by the controller's UI lasers. This UI is set as its own layer, and the lasers along with the UI appear automatically when using sxr.InputSlider() or sxr.InputDropdown(). When these components are active, the camera will only show things in the "InteractiveUI" layer (meaning the VR environment will temporarily disappear while the participant makes a selection). When the user clicks on the "Submit" button, the input of the Slider/Dropdown can be parsed with sxr.ParseInputUI(out output). ParseInputUI() will return "true" when the submit button is pressed and will return the output of the Slider/Dropdown to the variable defined as output. The camera will then automatically switch back to the environment with the UI hidden. See the included Sample Experiment (Package Manager -> simpleXR -> Samples) to see an example.