providefunctionnacatamalon
provide(key: string, value: T) => voidPublishes something for the other behaviours on the same object to use, under key.
For behaviours put together through a saved scene, where the two files do not know about each other and cannot import anything. Scene code written by hand should just import.
The convention that makes this readable: the key is the name of whoever publishes it, so
provide('spin', ...) is reached as useApi('spin') and named as requires: ['spin']. One
word, three places.
Parámetros
keystringWhat to call it. The publisher's own name, by convention.
valueTAnything: usually a small set of functions the others may call.
Ejemplo
registerScript('spin', (self) => {
let running = true;
provide('spin', {
stop: () => { running = false; },
start: () => { running = true; },
isRunning: () => running,
});
useUpdate((delta) => { if (running) self.drawables[0].transform.rotation += delta; });
});