Created
March 15, 2022 18:12
-
-
Save thisredone/b364f62c909fb63f7fe24b2ec2a94bab to your computer and use it in GitHub Desktop.
Violentmonkey script for Uranus Editor Scripting for Playcanvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const loadScriptAsync = function (url) { | |
return new Promise((resolve) => { | |
var tag = document.createElement('script'); | |
tag.onload = function () { | |
resolve(); | |
}; | |
tag.onerror = function () { | |
throw new Error('failed to load ' + url); | |
}; | |
tag.async = true; | |
tag.src = url; | |
document.head.appendChild(tag); | |
}); | |
}; | |
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | |
const waitForInit = async () => { | |
let timeout = 15000; | |
while (!editor?.call('viewport:app')?.assets?.find('uranus-editor-sdk.js')) { | |
await delay(5); | |
timeout -= 5; | |
if (timeout <= 0) return false; | |
} | |
return true; | |
}; | |
const bootUranusEditor = async () => { | |
const loaded = await waitForInit(); | |
if (!loaded) return; | |
const app = editor.call('viewport:app'); | |
const sdkUrl = app.assets.find('uranus-editor-sdk.js'); | |
if (!sdkUrl) return; | |
await loadScriptAsync(sdkUrl.getFileUrl()); | |
startUranusEditor(); | |
}; | |
const startUranusEditor = function () { | |
if (editor && Uranus && Uranus.Editor) { | |
const modules = [ | |
// { | |
// moduleName: 'Ammo', | |
// glueUrl: 'ammo.wasm.js', | |
// wasmUrl: 'ammo.wasm.wasm', | |
// fallbackUrl: 'ammo.js', | |
// loaded: false, | |
// }, | |
]; | |
Uranus.Editor.loadModules(modules).then(function () { | |
// Uranus.Editor.startAppLoop(true, modules[0].loaded === true); | |
// Uranus.Editor.batchExecuteScripts(); | |
}); | |
} | |
}; | |
bootUranusEditor(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment