Using the Liminal SDK - LiminalVR/DeveloperWiki GitHub Wiki
The QuickStart for SDK Integration guides you through the process of importing the Liminal SDK and setting up your project.
- During scene setup a new object named 'ExperienceApp' is created at the root of the scene. This becomes the parent of any existing GameObjects within the scene.
- If you create any new GameObjects after this process, they should also be parented under the 'ExperienceApp' root object.
When running within the Liminal App, an Experience begins with loading the scene from the .limapp
package. This process is similar to loading a Unity Scene. However the initialization sequence has some key differences.
-
Awake()
will be called in sequence on any active GameObjects. At this point the GameObjects have not yet been deserialized and other GameObjects may not yet be active. YourAwake()
methods should not depend on serialized data or on other objects being active in the scene (e.g.FindObjectOfType()
). - GameObjects are then disabled with a
SetActive(false)
call -
[Serializable]
classes are now deserialized - GameObjects are re-enabled with a
SetActive(true)
call - The
ExperienceApp.Initializing
event is fired
ExperienceApp.Initializing
is raised after the ExperienceApp
finishes initializing.
Important: If your Awake()
function relies on an object being alive in the scene such as FindObjectOfType()
, then you may experience null
reference issues when the Experience begins.
Solution : Perform any initialization that depends on serialized data or on other GameObjects in a listener to ExperienceApp.Initializing
. The event can be subscribed to from Awake()
:
using Liminal.SDK.Core;
using UnityEngine;
public class ExampleScript : MonoBehaviour
{
private void Awake()
{
ExperienceApp.Initializing += Init;
}
private void Init()
{
//Initialize my class
}
}
The SDK comes with Demo Scenes which can be located in your project under Liminal/Examples/
. Each of the scenes showcase different features of the SDK.
The Liminal.SDK.VR.VRDevice
class allows developers to track input from VR devices in a similar way to Unity's Input class. To monitor the active input device e.g. for button presses, use VRDevice.Device.PrimaryInputDevice
.
using Liminal.SDK.VR;
using Liminal.SDK.VR.Input;
using UnityEngine;
public class VRInputExample : MonoBehaviour
{
private void Update()
{
//Get the primaryInput
var primaryInput = VRDevice.Device.PrimaryInputDevice;
if (primaryInput.GetButtonUp(VRButton.One))
{
//Trigger has been pressed and released
}
}
}
The Liminal SDK uses a custom input module that allows users to interact with Unity UI elements the same way the mouse does. If it is not working, please ensure that the EventSystem
has a VRPointerInputModule
component.
Pointers use the VRPhysicsRaycaster
component (found in the scene under VRAvatar > Auxiliaries
). This allows 3D objects to become interactive in the same way as Unity UI elements by implementing the IPointerClickHandler
interface.
Important: The object must have a 3D collider such as MeshCollider
or BoxCollider
.
using UnityEngine;
using UnityEngine.EventSystems;
public class CubePointerUpExample : MonoBehaviour, IPointerClickHandler
{
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("The object has been clicked");
}
}
The GazeInput
component of the VRAvatar
GameObject allows VR devices without a controller to interact with Unity UI & 3D objects via gaze. You can set the Hover Duration
field of this component to control how long gaze remains on an object before an event is dispatched.
The GazeInput.ActivationPolicy
field defines when gaze input is used. Setting to Never
disabled gaze input completely, even if no other controller is in use.
- Locate the controller from
VRAvatar > PrimaryHand > Anchor > Controller
- Remove the controller
- Add your own model on the
Anchor
object
Important: If you do not wish a controller to be visible in your Experience, remove VRAvatar > PrimaryHand > Anchor > Controller
This process will generate a .limapp file of your scene.
Important: Open the console log before building your Experience. The build process can take a while, so be patient. Once complete, the log will display that the limapp build process was successful.
From the Liminal Build Window:
- Select the platform
- Click Build.
Important If you not on the Platform you selected, all assets will have to be imported again to the platform, so this process will take a long time. It is advised to build for your current platform.