A notification of your own design
Updated
A script defines a shop notification built from UI entities, with Buy and Cancel buttons that answer it.
Press Open shop, then Buy or Cancel in the panel that appears.
A notification of your own design
#pragma lifecycle(startup)
// Scene: other scripts emit 'shop/open' to offer an item, and 'coin' when a coin is collected.let answerShop;
function startup() { // A floating "+10" that shows where a coin was collected. NotificationService.define('score', (data) => { const label = new UILabelEntity(); label.getComponent(UILabelComponent).setProps({ text: `+${data.points}`, fontSize: 32, color: '#facc15' }); return label; });
// A small shop panel with two buttons. NotificationService.define('shop', (data, answer) => { answerShop = answer; const panel = new UIPanelEntity(); const title = new UILabelEntity(); title.getComponent(UILabelComponent).setProps({ text: `Buy ${data.item}?`, fontSize: 20 }); const buy = new UIButtonEntity(); buy.getComponent(UIButtonComponent).setProps({ text: 'Buy' }); buy.addComponent(new SignalEmitterComponent({ signal: 'shop:buy' })); const cancel = new UIButtonEntity(); cancel.getComponent(UIButtonComponent).setProps({ text: 'Cancel', variant: 'subtle' }); cancel.addComponent(new SignalEmitterComponent({ signal: 'shop:cancel' })); panel.add(title, buy, cancel); return panel; });
// Wire the buttons once, here, not inside build. on('shop:buy', () => answerShop?.('buy')); on('shop:cancel', () => answerShop?.('cancel')); on('shop:answer', (event) => { if (event.eventType === EventType.UINotification.Action && event.data.action === 'buy') log('sword bought'); });
on('coin', (data) => { NotificationService.show('score', { points: 10 }, { position: data.position, duration: 1.5 }); }); on('shop/open', () => { NotificationService.show('shop', { item: 'Sword' }, { anchor: 'bottom-right', duration: Infinity, signal: 'shop:answer' }); });}How it works
Section titled “How it works”The script is explained step by step in A notification of your own design.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
CustomNotification.xrproj