Sample: Reading Game Elements
You can use the PlayURPlugin.instance.ElementEnabled
function to return a boolean value for if the requested element is enabled in the current configuration.
The requested element passed as a parameter to this function uses the generated Element
enum.
using PlayUR;
public class OnlyShowIfElementIsEnabled : PlayURBehaviour
{
public Element elementToCheck;
public override void Start()
{
base.Start();
//ensure the object is not visible on startup
gameObject.SetActive(false);
}
public override void OnReady()
{
gameObject.SetActive(PlayURPlugin.instance.ElementEnabled(elementToCheck));
}
}
You can also use the PlayURPlugin.instance.ListElements
function to return a list of enabled elements for the current configuration.
using PlayUR;
public class DebugElements : PlayURBehaviour
{
public override void OnReady()
{
Debug.Log(string.Join("\n",PlayURPlugin.instance.ListElements()));
}
}
Unity Sample Requirements
You can import this sample from the Unity Package Manager. For the code to run, you will need a game set up in Unity (see Getting Started), and the following configured for the game on the PlayUR Dashboard:
- The Elements Feature enabled in the Game Settings
- Experiments: At least one
- Experiment Groups: At least one
- Elements: At least one