API Reference

Class List

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.

Summary

Methods

addAdd Attribute
getGet object with attribute arguments.
hasDetect if Attribute is added.
removeRemove Attribute.

Details

Constructor

ScriptAttributes(scriptType)

Parameters

scriptTypeScriptTypeScript 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

nameStringName of an attribute
argsObjectObject with Arguments for an attribute
args.typeStringType of an attribute value, list of possible types: boolean, number, string, json, asset, entity, rgb, rgba, vec2, vec3, vec4, curve
args.default?Default attribute value
args.titleStringTitle for Editor's for field UI
args.descriptionStringDescription for Editor's for field UI
args.placeholderString, String[]Placeholder for Editor's for field UI. For multi-field types, such as vec2, vec3, and others use array of strings.
args.arrayBooleanIf attribute can hold single or multiple values
args.sizeNumberIf attribute is array, maximum number of values can be set
args.minNumberMinimum value for type 'number', if max and min defined, slider will be rendered in Editor's UI
args.maxNumberMaximum value for type 'number', if max and min defined, slider will be rendered in Editor's UI
args.precisionNumberLevel of precision for field type 'number' with floating values
args.assetTypeStringName of asset type to be used in 'asset' type attribute picker in Editor's UI, defaults to '*' (all)
args.curvesString[]List of names for Curves for field type 'curve'
args.colorStringString 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
args.enumObject[]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

nameStringName of an attribute

Returns

Object Arguments with attribute properties

has(name)

Detect if Attribute is added.

if (PlayerController.attributes.has('fullName')) {
    // attribute `fullName` is defined
});

Parameters

nameStringName of an attribute

Returns

Boolean True if Attribute is defined

remove(name)

Remove Attribute.

PlayerController.attributes.remove('fullName');

Parameters

nameStringName of an attribute

Returns

Boolean True if removed or false if not defined