API Reference

Class List

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

scriptTypetypeof(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

namestring

Name of an attribute.

argsobject

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.titlestring

Title for Editor's for field UI.

args.descriptionstring

Description 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.arrayboolean

If attribute can hold single or multiple values.

args.sizenumber

If attribute is array, maximum number of values can be set.

args.minnumber

Minimum value for type 'number', if max and min defined, slider will be rendered in Editor's UI.

args.maxnumber

Maximum value for type 'number', if max and min defined, slider will be rendered in Editor's UI.

args.precisionnumber

Level of precision for field type 'number' with floating values.

args.stepnumber

Step value for type 'number'. The amount used to increment the value when using the arrow keys in the Editor's UI.

args.assetTypestring

Name 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.colorstring

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.

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

namestring

Name 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

namestring

Name of an attribute.

Returns

boolean

True if Attribute is defined.

remove(name)

Remove Attribute.

PlayerController.attributes.remove('fullName');

Parameters

namestring

Name of an attribute.

Returns

boolean

True if removed or false if not defined.