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.

Constructors

Methods

Constructors

Methods

  • Add Attribute.

    Parameters

    • name: string

      Name of an attribute.

    • args: {
          "args.default"?: any;
          array?: boolean;
          assetType?: string;
          color?: string;
          curves?: string[];
          description?: string;
          enum?: object[];
          max?: number;
          min?: number;
          placeholder?: string | string[];
          precision?: number;
          schema?: object[];
          size?: number;
          step?: number;
          title?: string;
          type:
              | "string"
              | "number"
              | "boolean"
              | "rgb"
              | "curve"
              | "json"
              | "vec2"
              | "vec3"
              | "vec4"
              | "entity"
              | "asset"
              | "rgba";
      }

      Object with Arguments for an attribute.

      • Optionalargs.default?: any
      • Optionalarray?: boolean

        If attribute can hold single or multiple values.

      • OptionalassetType?: string

        Name of asset type to be used in 'asset' type attribute picker in Editor's UI, defaults to '*' (all).

      • Optionalcolor?: string

        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.

      • Optionalcurves?: string[]

        List of names for Curves for field type 'curve'.

      • Optionaldescription?: string

        Description for Editor's for field UI.

      • Optionalenum?: object[]

        List of fixed choices for field, defined as array of objects, where key in object is a title of an option.

      • Optionalmax?: number

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

      • Optionalmin?: number

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

      • Optionalplaceholder?: string | string[]

        Placeholder for Editor's for field UI. For multi-field types, such as vec2, vec3, and others use array of strings.

      • Optionalprecision?: number

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

      • Optionalschema?: 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.

      • Optionalsize?: number

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

      • Optionalstep?: number

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

      • Optionaltitle?: string

        Title for Editor's for field UI.

      • type:
            | "string"
            | "number"
            | "boolean"
            | "rgb"
            | "curve"
            | "json"
            | "vec2"
            | "vec3"
            | "vec4"
            | "entity"
            | "asset"
            | "rgba"

        Type of an attribute value. Can be:

        • "asset"
        • "boolean"
        • "curve"
        • "entity"
        • "json"
        • "number"
        • "rgb"
        • "rgba"
        • "string"
        • "vec2"
        • "vec3"
        • "vec4"

    Returns void

    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 }
    ]
    }]
    });
  • Get object with attribute arguments. Note: Changing argument properties will not affect existing Script Instances.

    Parameters

    • name: string

      Name of an attribute.

    Returns object

    Arguments with attribute properties.

    // changing default value for an attribute 'fullName'
    var attr = PlayerController.attributes.get('fullName');
    if (attr) attr.default = 'Unknown';
  • Detect if Attribute is added.

    Parameters

    • name: string

      Name of an attribute.

    Returns boolean

    True if Attribute is defined.

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