pc.ScriptAttributes
Container of Script Attribute definitions. Implements an interface to add/remove attributes and store their definition for a pc.ScriptType. Note: An instance of pc.ScriptAttributes is created automatically by each pc.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)
Parameters
| scriptType | typeof pc.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 }
]
});
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. |
| 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. |
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.