Constructor
new ScriptRegistry(app)
Create an instance of a pc.ScriptRegistry.
Note: PlayCanvas scripts can access the Script Registry from inside the application with pc.Application#scripts pc.ADDRESS_REPEAT.
Parameters:
Name | Type | Description |
---|---|---|
app |
pc.Application | Application to attach registry to. |
- Source:
Methods
add(script) → {Boolean}
Add ScriptType to registry.
Note: when pc.createScript is called, it will add the ScriptType to the registry automatically.
If a script already exists in registry, and the new script has a `swap` method defined,
it will perform code hot swapping automatically in async manner.
Parameters:
Name | Type | Description |
---|---|---|
script |
ScriptType | Script Type that is created using pc.createScript |
- Source:
Returns:
True if added for the first time or false if script already exists
- Type
- Boolean
Example
var PlayerController = pc.createScript('playerController');
// playerController Script Type will be added to pc.ScriptRegistry automatically
app.scripts.has('playerController') === true; // true
get(name) → {ScriptType}
Get ScriptType by name.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of a ScriptType. |
- Source:
Returns:
The Script Type if it exists in the registry or null otherwise.
- Type
- ScriptType
Example
var PlayerController = app.scripts.get('playerController');
has(name) → {Boolean}
Check if a ScriptType with the specified name is in the registry.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of a ScriptType |
- Source:
Returns:
True if ScriptType is in registry
- Type
- Boolean
Example
if (app.scripts.has('playerController')) {
// playerController is in pc.ScriptRegistry
}
list() → {Array.<ScriptType>}
Get list of all ScriptTypes from registry.
- Source:
Returns:
list of all ScriptTypes in registry
- Type
- Array.<ScriptType>
Example
// logs array of all Script Type names available in registry
console.log(app.scripts.list().map(function(o) {
return o.name;
}));
remove(name) → {Boolean}
Remove ScriptType.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of a ScriptType to remove |
- Source:
Returns:
True if removed or False if already not in registry
- Type
- Boolean
Example
app.scripts.remove('playerController');