Scripting: Exposing Editable Variables
Description
Nominal Studio displays parameters and outputs from components in the details panel. These parameters are public values that are exposed from the components written in the C# scripting backend. However, only the variables that have an EditableVariable
attribute added to them will be exposed to Studio’s automated variable detection system. This works for both fields and properties in C#.
Exposing Variables
In the custom C# component, any property or field can be marked as EditableVariable
, provided that it is public and non-static. This can be done by adding the following attribute to the variable, on the line above:
[EditableVariable("-")]
public double MyVariable;
The editable variable flag works for any standard and Nominal data type. These include:
- Booleans (bool)
- Integers (int)
- Decimals (double)
- Vector3 (x, y, z)
- Matrix3 (3x3 matrix)
- Text (string)
Additionally, certain parameters can be added to the attribute that will determine how they are displayed on the panel. The required one is the units, which are defined in the code above. The units describe what the unit is for that variable. If no unit exists, it is recommended to put "-"
in the parameter. Optional parameters include:
- ReadOnly: If this is enabled, the variable will be disabled in Studio and will not be edited from the panel. This is useful for output data that should not be changed by the user.
- MinValue: The minimum value that the field can be. This only applies to the integer and decimal number types and by default will be disabled.’
- MaxValue: The maximum value that the field can be. This only applies to the integer and decimal number types and by default will be disabled.
- Category: The category type for the variable. This may be used in a future Studio release for filtering for data.
- DisplayName: This is a custom override name and the variable shown will use this name instead of the name of the variable that is used by default.
Some examples of using the flag are shown below.
// Displays the area of an object with a minimum value of 0
[EditableVariable("m^2", 0, DisplayName: "Custom Area")]
public double Area = 0.0;
// Displays some number between 1 and 10 with a custom category
[EditableVariable("-", 1, 10, Category: "Advanced")]
public int Factor = 5;
// Displays an output that is read-only and has been renamed for the widget
[EditableVariable("m", ReadOnly: true, DisplayName: "Output")]
public Vector3 SensedValue { get; private set; }
Warning
For this to work, the user must have set up their environment to compile C# code for Editor and export the components into Studio. This is covered in another document.