DOCUMENTATION / UX SESSION

UX Session

This system is responsible for the segmented user experiences that occur when an app is used.  For example, if you’re building a game, sessions could be the levels in your game.  Sessions in an educational experience could be a training module.  In our UXFoundation demo app, sessions are the period of time during which a user is placing Items in a Layout.  This system managers things like wor UI ViewSystems, spawning/destroying runtime objects in the scene.

UXSessionManager.cs

Inspector: Reference Objects

UXSession sessionPrefab

This is the session prefab that will be instantiated when a new session begins.

List<UXEnvironment> environments

On initialization, UXSessionManager parses through these environments and instantiates the ones where their platformType property matches the active UXPlatformType

Properties & Functions

IsActive() => bool

Returns “true” if there is an active session.

BeginSession(UXData sessionData = null)

Begins the session by instantiating a new sessionPrefab, calling BeginSession on the new session’s UXSession.cs component, and then notifies listeners by calling onSessionStarted.

EndSession()

Notifies listeners by calling onWillEndSession and then destroys the activeSession GameObject.

GetActiveSession() => UXSession

Returns the activeSession.

Spawner()

Public convenience access to the UXSpawner component that is attached to the UXSessionManager gameObject.

Delegates

onSessionStarted(UXData sessionData = null)

Notifies listeners when a new session has started.

onWillEndSession()

Notifies listeners right before the activeSession is ended.  Note: the activeSession gameObject is Destroyed directly after this, so this notification is useful for functionality like saving data.

UXSession

UXSession.cs

This prefab can be one of the more complicated UXFoundation implementations because of UXFoundation’s use of class inheritance with UXSession.cs.  As an example (and for the unique needs of the UXFoundation demo app), we’ve created the UXLayoutSession prefab and component that inherits from UXSession.  Check it out and then follow these steps to create your own custom session prefab.

Creating A Custom Session Prefab

The Easy Way

Refactor UXLayoutSession.cs with your own custom session code.

The Other Way:

  1. Duplicate the UXSession prefab in the project folder and rename the duplicate prefab with your desired Session name.
  2. Remove the UXSession component from the gameObject in the Inspector
  3. Create/Add a new component in the inspector and, in code, be sure to inherit from UXSession.
  4. Drag that prefab from the project folder to UXSessionManager’s sessionPrefab Inspector reference.
Virtual Functions & Overrides

UXSession has the following event-based virtual functions that you can be overridden/accessed.

BeginSession(UXData sessionDataToSet = null)

Sets the sessionData (the active Layout in the case of the UXFoundation demo app), childs the sessionData’s Transform to the UXSession’s Transform (for manipulation and tracking purposes), and activates the sessionData object.  Note: Override this function to trigger additional UXSession setup – for things like reporting, time tracking, scoring, etc when a session begins.

ONWillEndSession()

Childs the sessionData’s Transform back to its UXDataController Transform and deactivates the sessionData’s gameObject.  Note: Override this function to trigger additional UXSession wrap up – for things like reporting, saving, etc when a session ends.

Properties & Functions

UXData activeSessionData

This is the data that gets parented to the UXSession when a session begins and parented back to its UXDataController when a session ends.  This data object should be a session-level data object that can track all of the relevant information that your app needs to persist between sessions. 

UXLayoutSession

UXLayoutSession.cs

This is the UXFoundation demo app’s custom UXSession prefab.  It contains some virtual override examples that are worth paying attention to.  In the UXFoundation demo app, this component is what subscribes to Spawn events and responds by placing new Items.

Virtual Functions & Overrides

new void Start()

This overrides the Start() function of the inherited UXSession class.  Add your custom OnStart code here.

 new void OnDestroy()

This overrides the OnDestroy() function of the inherited UXSession class.  Add your custom OnDestroy() code here.

override void ONWillEndSession()

This overrides the ONWillEndSession() function of the inherited UXSession class.  Add your custom ONWillEndSession() code here.

UXEnvironment

UXEnvironment.cs

In AR/VR, there are quite a few variable combinations that require different environments – handheld AR, wearable AR, wearable VR, and in some cases handheld VR will all have their own combination of virtual and physical spatial considerations.  This prefab/component allows you to create unique environments for each context and have them automatically instantiated based on the active UXPlatformViewType.

Inspector: Reference Objects

UXPlatformViewType platformViewType

The UXSessionManager checks this property and instantiates an instance of this prefab when it matches the active UXPlatformViewType.

UXSpawner.cs

This is a component of the UX Session system that is found on the UXSessionManager gameObject.  It watches for onClick events registered by gameObjects where the hit’s transform name matches a custom List of SpawnTarget string names.  Note: Subscribe to UXSessionManager.instance.SpawnTarget()’s OnSpawnTriggered(Pose spawnPose, Transform spawnTarget) delegate to be notified with the hit’s Pose and Transform. 

Inspector: Settings

List<string> SpawnTargets

This is the list of strings that the Spawner will check the transform name of the hit target against in order to determine if a OnSpawnTriggered event has occurred.

bool uiBlockingEnabled

If true, clicks over gameObjects with the Layer “UI” will be ignored and the OnSpawnTriggered event will not occur.

Delegates

OnSpawnTriggered(Pose spawnPose, Transform spawnTarget)

Notifies listeners when an onClick event registers by gameObjects where the hit’s transform name matches a custom List of SpawnTarget string names and passes along the hit’s Pose and Transform for spawning purposes.