PlayUR Unity Plugin Documentation
The PlayUR Unity plugin is designed to integrate Unity projects with games defined on the PlayUR Platform. Use the links on the side to see the different classes available.
To learn how to integrate PlayUR into your Unity project, see the Getting Started Guide
Enabling the PlayUR Plugin in your Scenes
Ensure that you include the
PlayURPluginHelper prefab in any scene that you will be using PlayUR features. Within the editor, this prefab also allows you to run the game in Unity from your scene, automatically redirect to the
PlayURLogin scene, and then return to your scene (regardless of scene build order) after login is complete (including auto-login).
Most Important Classes
The bulk of the plugin implementation is in the following files:
- The main singleton containing most of the functions you will need.
- The MonoBehaviour script on the PlayURPluginHelper prefab that should be placed in all scenes, which makes testing the Unity Editor easier.
While you can call
PlayURPlugin functions from any class using
PlayURPlugin.instance, it is recommended to extend the
If you extend this class, you should override the
OnReady function. This function is called at the start of the scene once PlayUR is confirmed to have a
Configuration populated. Requests for things like the current experiment, element status, or parameter values will not work unless the configuration is ready.
If you want to call non-PlayUR code on
Start within a class which extends from
PlayURBehaviour, you should override the
Start function. It is important that you still call
base.Start(). In general,
base.Start() should be called at the end of the overriden
Start function, as if the PlayUR Plugin is already ready on Start, this will be called immediately.
PlayURBehaviour also has some neat shortcut properties to
PlayURPlugin, check the class reference.
Not using PlayURBehaviour
If you choose to just use a
MonoBehaviour, before calling any PlayUR functionality, you should check if the plugin is ready using the
PlayURPlugin.instance.IsReady property, or subscribing to the
PlayURPlugin.instance.OnReady event (the downside to this event is that it is not triggered if the plugin is already ready).
Working With Source Control
- The file
Assets/PlayURPlugin/Resources/PlayURClientSecret.assetshould not be committed to source control as it contains the client secret used to talk to the PlayUR servers.
AnalyticsColumnenums are generated based upon your game ID. Due to a limitation of generated files from Unity packages, these files are modified in the
Library/PackageCache/io.playur.unity@####folder. You do not need to commit these files to source control, however all collaborators will need to generate these enums themselves upon first opening the project via the
PlayUR -> Generate Enumsoption.