Sample: Reading User and Build Info
At times it may be useful to get access to the PlayUR User
object for the logged in user, or determine information about the build of the game that is currently running.
Users
You can access the logged in user via PlayURPlugin.instance.user
. This allows you to access simple fields like their name
.
You might also like to determine if the user is a "Owner" of the current game (i.e. they are part of the research team), to allow them access to debugging information, special modes, etc. In this sample behaviour, an object is made visible only to Game Owners using the IsGameOwner
field:
using PlayUR;
public class OnlyShowIfIsOwner : PlayURBehaviour
{
public override void Start()
{
gameObject.SetActive(false);
base.Start();
}
public override void OnReady()
{
gameObject.SetActive(PlayURPlugin.instance.user.IsGameOwner);
}
}
You can even call Logout()
on the user object.
For full information, visit the API Documentation for the User Class.
Browser Info
If running a browser build, you can get information via PlayURPlugin.browserInfo
. This will be the browser name (e.g. Chrome
) and version number (e.g. 123
).
Managing Builds
PlayUR lets you manage builds via the Builds tab, for example to revert to a previous build, or to lock to a specific build/build-branch for a given Experiment.
When creating a build in Unity, you are prompted to enter a Build Branch. By default this is main
, however you may want to tag a build with a different branch name, and then associate that branch name with a certain Experiment or Experiment Group via the settings page for the experiment or group (and setting the Build Branch
). You can also for an experiment or group to use a specific Build ID
.
This functionality is particularly useful if you want to "lock" code down on an older experiment, and only allow newer code (builds) to effect newer experiments.
You can determine the current build number or branch name with the following values:
PlayURPlugin.instance.CurrentBuildID
PlayURPlugin.instance.CurrentBuildBranch
Unity Sample Requirements
You can import this sample from the Unity Package Manager. This code will work in any project where at least one Build has been made.