DOCUMENTATION / UX DATA

UX Data

This system is responsible for the creation, hydration, tracking, and deletion of all of the various types of data.  It consists of a data manager that managers a controller for each type of data.  Those controllers are responsible for creating/managing/deleting their respective data objects, and the data objects are the source of informational truth that’s shared between the UI and the session objects.

UXDataManager.cs

Properties & Functions

GetDataOfTypeWithName(DataType dataType, string objectName) => Transform

Returns the Transform UXData object of the DataType provided with the transform name that matches the provided objectName.

GetDataOfTypeWithUID(DataType dataType, string uid) => Transform

Returns the Transform of the UXData object of the DataType provided with the uid that matches the provided uid.

GetAllDataOfType(DataType dataType) => List<UXData>

Returns all UXData objects of the provided DataType.

GetDataControllerForType(DataType dataType) => UXDataController

Returns the UXDataController of the provided DataType.

GetNewDataObjectsOfType(int numberOfObjects, DataType dataType) => List<Transform>

Creates and then returns a List of the given number of new UXData objects of the given type.

GetDataCountForType(DataType dataType) => int

Returns the number of UXData objects of the provided DataType

SaveData()

A convenience function that allows you to hook into the UXData system with whatever saving functionality you would like to implement.  Note: there are currently no “save to disk” features in UXFoundation.

ClearAllData()

Deletes all UXData objects of all types.  Note: This does not delete their UXDataControllers.

GetLocalUser() => UXUser

Returns the UXUser object that has the “isLocalUser” bool property set to true.  Note: this feature only works if you set “isLocalUser” to true on the local user UXUser object and then set isLocalUser to false on all other UXUser objects.

UXDataController

UXDataController.cs

This prefab is a part of the UX Data system.  

Creating A Custom Data Type
  1. Add the name of the new data type to the “DataType” enum in the UXDataManager.cs script
  2. Add this prefab as a child of the UXDataManager in the hierarchy
  3. Select the DataType in the dropdown on the UXDataController
  4. Set up your UXData object in one of the following 2 ways
    1. Add a UXData.cs component to the UXData child in the hierarchy and choose the DataType from the dropdown
    2. OR – Create a new, custom data component that inherits from UXData, add that component to the UXData child in the hierarchy, and choose the DataType from the dropdown

Note: The UXDataController.cs component is a primarily internal script.  We recommend accessing UXData through the static UXDataManager instance variable.

UXData

UXData.cs

This is one of the more complicated, but powerful component implementations in the UXFoundation system.  We don’t use a lot of inheritance, but in this case we do simply because it keeps things clean when passing around data and accessing the various properties and functionalities.

Note: What’s unique about the UXData prefab is that it is technically a child gameObject of the UXDataController prefab.  When creating a new Data Type using the instructions in the UXDataController section above, this object is a child of that prefab and therefore we recommend creating a prefab variant of the UXDataController for each new UXData type.  

In the Inspector, in the “Settings” section of UXData component, there is a bool “isSourcePrefab” that is set to true – to represent the fact that all other data of this type will be a replication of this gameObject.  This isSourcePrefab bool is internally set to false for all runtime instances of this UXData object and the “source prefab” instance is ignored in all Count, GetAll, and DeleteAll functions.

Properties & Functions

NotifyListeners(string updateTag)

Call this function to notify and listeners that this UXData object has been updated with new data. Note: To receive this notification, subscribe to the onDataUpdated(UXData uxData, string updateTag) function.

GetUID() => string

Returns the UID.

OverrideUID(string uidToSet)

Sets the UID.  Note: Only do this if you’re loading data and already have the UID or if you prefer to track using your own identifier system.

GetName() => string

Returns the object name.

SetName(string newName)

Sets the object name.

ShowModel(bool show)

This is a convenience function for Spatial/3D data objects.  If the UXData object has a child called “Model”, it activates/deactivates the gameObject.

GetInstanceOfObject(Transform instanceParent) => Transform

This is a convenience function for Spatial/3D data objects.  If the UXData object has a child called “Model”, it creates a duplicate instance of the object.  Note: we recommend tracking duplicate instances of objects in a UXLayout data object.

GetDataController() => Transform

Returns the UXData’s parent UXDataController transform.

UXUser.cs

Every app has a minimum of 1 user.  Many have multiple users.  We’ve created a convenience data type for this with all of the most common properties (firstName, lastName, email, userImage, etc) and a set of arbitrary properties (like “job”, “age”, etc) that can be easily replaced with your own user data.

Properties & Functions

UXUserData data

This is a public reference to a Serializable UXUserData object that allows downloaded/imported JSON objects to map directly to it by using Unity’s JsonUtility.  Just change these properties to match your downloaded json tree.  The default properties we’re using in the demo app are: id, token, first_name, last_name, email, job_title, salary, age, profile_pic, userImage.

bool isLocalUser

Mark this as true if you would like the UXDataManager to recognize this user as the local user. Note: UXDataManager returns the first user with this variable marked “true”, so if you have multiple users, be sure to mark this property “false” on the others.

Sprite temporaryImage

Set this temporary image on the prefab in the inspector and it will use this image if there is a delay and or issue with downloading the userImage.

InitializeWithData(UXUserData userDataToSet, bool isLocalUser = false)

Externally, use JsonUtility to map your downloaded json data to a new instance of a UXUserData object.  Pass that object into this function in order to initialize the UXUser with that data.  Note: This is also the recommended point to declare isLocalUser, so we’ve added that as a method variable.

GetProfileImage() => Sprite

Returns the profile image sprite.

GetFullName() => string

Combines the first_name, a space, and the last_name.  We recommend editing this function if you would like to support more complex naming conventions.

SetTransformName()

Sets the transform name to the GetFullName() string.

UXLayout.cs

The UXFoundation demo app is an AR/VR furniture placement app that requires a Layout data type to track the placement of furniture items.  If your project doesn’t track the layout of items (a high probability, we realize), we recommend refactoring UXLayout to whatever your session-level data type might be.  For example “Level” for a game, “Cart” for a shopping app, “Chat” for a messaging app.

Properties & Functions

string title

Public access to the name of the layout

setNewLayoutName()

Creates and sets a new layout name based on the number of UXLayout data objects that exist

GetItemCountString() = > string

Returns the number of Items followed by “ Items”.

ItemCount() => int

Returns the number of Items in the Layout

HasItems() => bool

Returns “true” if the Layout has Items.

UXItem.cs

The UXFoundation demo app is an AR/VR furniture placement app that requires an Item data type to track what’s placed in a UXLayout during a UXSession.  If your project doesn’t track the layout of items (a high probability, we realize), we recommend refactoring UXItem to whatever your item-level data type might be.  For example “Actors” for a game, “Item” (still works) for a shopping app, “Message” for a messaging app.

Properties & Functions

Sprite icon

Public access to the 2D image Sprite for the UI to use as a representation of the 3D object.

string title

Public access to the name of the Item