Class: ScriptAttributes

pc.ScriptAttributes

Container of Script Attribute definitions. Implements an interface to add/remove attributes and store their definition for a ScriptType. Note: An instance of pc.ScriptAttributes is created automatically by each ScriptType.

Constructor

new ScriptAttributes(scriptType)

Parameters:
Name Type Description
scriptType ScriptType Script Type that attributes relate to.
Source:

Methods

add(name, args)

Add Attribute
Parameters:
Name Type Description
name String Name of an attribute
args Object Object with Arguments for an attribute
Properties
Name Type Attributes Description
type String Type of an attribute value, list of possible types: boolean, number, string, json, asset, entity, rgb, rgba, vec2, vec3, vec4, curve
default ? <optional>
Default attribute value
title String <optional>
Title for Editor's for field UI
description String <optional>
Description for Editor's for field UI
placeholder String | Array.<String> <optional>
Placeholder for Editor's for field UI. For multi-field types, such as vec2, vec3, and others use array of strings.
array Boolean <optional>
If attribute can hold single or multiple values
size Number <optional>
If attribute is array, maximum number of values can be set
min Number <optional>
Minimum value for type 'number', if max and min defined, slider will be rendered in Editor's UI
max Number <optional>
Maximum value for type 'number', if max and min defined, slider will be rendered in Editor's UI
precision Number <optional>
Level of precision for field type 'number' with floating values
step Number <optional>
Step value for type 'number'. The amount used to increment the value when using the arrow keys in the Editor's UI.
assetType String <optional>
Name of asset type to be used in 'asset' type attribute picker in Editor's UI, defaults to '*' (all)
curves Array.<String> <optional>
List of names for Curves for field type 'curve'
color String <optional>
String of color channels for Curves for field type 'curve', can be any combination of `rgba` characters. Defining this property will render Gradient in Editor's field UI
enum Array.<Object> <optional>
List of fixed choices for field, defined as array of objects, where key in object is a title of an option
Source:
Examples
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 }
    ]
});

get(name) → {Object}

Get object with attribute arguments. Note: Changing argument properties will not affect existing Script Instances.
Parameters:
Name Type Description
name String Name of an attribute
Source:
Returns:
Arguments with attribute properties
Type
Object
Example
// changing default value for an attribute 'fullName'
var attr = PlayerController.attributes.get('fullName');
if (attr) attr.default = 'Unknown';

has(name) → {Boolean}

Detect if Attribute is added.
Parameters:
Name Type Description
name String Name of an attribute
Source:
Returns:
True if Attribute is defined
Type
Boolean
Example
if (PlayerController.attributes.has('fullName')) {
    // attribute `fullName` is defined
});

remove(name) → {Boolean}

Remove Attribute.
Parameters:
Name Type Description
name String Name of an attribute
Source:
Returns:
True if removed or false if not defined
Type
Boolean
Example
PlayerController.attributes.remove('fullName');