Luna Playground supports in-browser customisation of playables. This is achieved by the use of Playground Fields. Playground Fields are values that are exposed in Playground Editor as separate controls that allow developers to change some variables without rebuilding the playable.
1. Open playground.json configuration file and locate
Each field is defined as a simple JSON object residing under specific
class name and
field name. Let's take this by example: consider the below
The name of the class (
MyClass in the above example) and the field (
MyField above) are arbitrary - feel free to use whatever makes sense in your setup. Multiple fields can share the same class name, but the pair class name + field name should be unique. Please keep in mind, however, that updating the playable (uploading a new archive in the place of the previously uploaded one) will take those in consideration trying to match the fields based on the combination of class and field name. For instance, if you keep names the same and do not change field type, it will be retained in all versions keeping the values previously set through the playground.
Let us summarize all available field types:
|string||A string value, can be multi-line|
|int32||An int32 value|
|float||A floating-point value|
|bool||A boolean value|
|enum||An integer value with preset list of options|
|color||An RGBA color value|
|vector2||A 2 component vector|
|vector3||A 3 component vector|
|vector4||A 4 component vector|
You can add a constraints object to a field to set limits for its values, this will stop values entered in Playground going under/over the set min/max.
An example of adding a constraints object to a field can be seen below.
Setting int/float constraints
If you make use of both the
value_max constraints, your field will appear as a range slider in Luna Playground.
value_step can also be added in order to control at what value the slider increments at, though it is not required in order for a slider to function.
By default sliders in Luna Playground will increment by 1 if the slider is affecting an int value, and for float values the default is the difference between the minimum and maximum slider values divided by 100
(max - min)/100.
|value_min||int32/float value||Set a minimum value for an int or float field|
|value_max||int32/float value||Set a maximum value for an int or float field|
|value_step||int32/float value||Set the increment value for an int or float field|
Setting array constraints
If you have an array of Vectors or Colors, you can set the minimum and/or maximum length of said array using the constraints below. Arrays can function in Playground without min or max lengths set, however they will not have limits on the amount of items allowed to be entered into them.
|array_min_length||int32/float value||Set a minimum value for an int or float field|
|array_max_length||int32/float value||Set a maximum value for an int or float field|
In order to grab the value of the Playground Field, please use
Luna.Unity.Playground.get. Since you might want to test your playable locally, don't forget to check for Luna API presence before calling the API, i.e.
Luna.Unity.Playground.get will return a value of corresponding type: if the Playground Field is defined to be a string, a string will be returned; if it's vector, an array will be returned and so on. Color fields allow you to pass an additional, 4th argument to
Luna.Unity.Playground.get with the value set to
rgba which will make it return a CSS-compatible string corresponding to the color, i.e.
Feel free to check the example residing at https://github.com/LunaCommunity/Playable-Examples/tree/master/full for a minimal setup of a playable using Playground Fields.