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.

      • args.default: any
      • array: boolean

        If attribute can hold single or multiple values.

      • assetType: string

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

      • color: 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.

      • curves: string[]

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

      • description: string

        Description for Editor's for field UI.

      • enum: object[]

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

      • max: number

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

      • min: number

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

      • placeholder: string | string[]

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

      • precision: number

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

      • schema: 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.

      • size: number

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

      • step: number

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

      • title: 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';