• Register a existing class type as a Script Type to ScriptRegistry. Useful when defining a ES6 script class that extends ScriptType (see example).

    Parameters

    • script: typeof ScriptType

      The existing class type (constructor function) to be registered as a Script Type. Class must extend ScriptType (see example). Please note: A class created using createScript is auto-registered, and should therefore not be pass into registerScript (which would result in swapping out all related script instances).

    • Optionalname: string

      Optional unique name of the Script Type. By default it will use the same name as the existing class. If a Script Type with the same name has already been registered and the new one has a swap method defined in its prototype, then it will perform hot swapping of existing Script Instances on entities using this new Script Type. Note: There is a reserved list of names that cannot be used, such as list below as well as some starting from _ (underscore): system, entity, create, destroy, swap, move, scripts, onEnable, onDisable, onPostStateChange, has, on, off, fire, once, hasEvent.

    • Optionalapp: AppBase

      Optional application handler, to choose which ScriptRegistry to register the script type to. By default it will use Application.getApplication() to get current AppBase.

    Returns void

    // define a ES6 script class
    class PlayerController extends pc.ScriptType {

    initialize() {
    // called once on initialize
    }

    update(dt) {
    // called each tick
    }
    }

    // register the class as a script
    pc.registerScript(PlayerController);

    // declare script attributes (Must be after pc.registerScript())
    PlayerController.attributes.add('attribute1', {type: 'number'});