ScriptAttributes
Container of Script Attribute definitions. Implements an interface to add/remove attributes and store their definition for a ScriptType. Note: An instance of ScriptAttributes is created automatically by each ScriptType.
Summary
Methods
add | Add Attribute. |
get | Get object with attribute arguments. |
has | Detect if Attribute is added. |
remove | Remove Attribute. |
Details
Constructor
ScriptAttributes(scriptType)
Create a new ScriptAttributes instance.
Parameters
scriptType | typeof(ScriptType) | Script Type that attributes relate to. |
Methods
add(name, args)
Add Attribute.
PlayerController.attributes.add('fullName', {
type: 'string'
});
PlayerController.attributes.add('speed', {
type: 'number',
title: 'Speed',
placeholder: 'km/h',
default: 22.2
});
PlayerController.attributes.add('resolution', {
type: 'number',
default: 32,
enum: [
{ '32x32': 32 },
{ '64x64': 64 },
{ '128x128': 128 }
]
});
PlayerController.attributes.add('config', {
type: 'json',
schema: [{
name: 'speed',
type: 'number',
title: 'Speed',
placeholder: 'km/h',
default: 22.2
}, {
name: 'resolution',
type: 'number',
default: 32,
enum: [
{ '32x32': 32 },
{ '64x64': 64 },
{ '128x128': 128 }
]
}]
});
Parameters
name | string | Name of an attribute. |
args | object | Object with Arguments for an attribute. |
args.type | "boolean", "number", "string", "json", "asset", "entity", "rgb", "rgba", "vec2", "vec3", "vec4", "curve" | Type of an attribute value. Can be:
|
args.default | * | Default attribute value. |
args.title | string | Title for Editor's for field UI. |
args.description | string | Description for Editor's for field UI. |
args.placeholder | string, string[] | Placeholder for Editor's for field UI. For multi-field types, such as vec2, vec3, and others use array of strings. |
args.array | boolean | If attribute can hold single or multiple values. |
args.size | number | If attribute is array, maximum number of values can be set. |
args.min | number | Minimum value for type 'number', if max and min defined, slider will be rendered in Editor's UI. |
args.max | number | Maximum value for type 'number', if max and min defined, slider will be rendered in Editor's UI. |
args.precision | number | Level of precision for field type 'number' with floating values. |
args.step | number | Step value for type 'number'. The amount used to increment the value when using the arrow keys in the Editor's UI. |
args.assetType | string | Name of asset type to be used in 'asset' type attribute picker in Editor's UI, defaults to '*' (all). |
args.curves | string[] | List of names for Curves for field type 'curve'. |
args.color | string | String of color channels for Curves for field type 'curve',
can be any combination of |
args.enum | object[] | List of fixed choices for field, defined as array of objects, where key in object is a title of an option. |
args.schema | object[] | List of attributes for type 'json'. Each attribute description is an object with the same properties as regular script attributes but with an added 'name' field to specify the name of each attribute in the JSON. |
get(name)
Get object with attribute arguments. Note: Changing argument properties will not affect existing Script Instances.
// changing default value for an attribute 'fullName'
var attr = PlayerController.attributes.get('fullName');
if (attr) attr.default = 'Unknown';
Parameters
name | string | Name of an attribute. |
Returns
objectArguments with attribute properties.