I’m working on a prototype that involves a little bit of tinkering with Unity’s generated javascript code. Specifically, I can make a development build, make some tweaks to the [build].wasm.framework.unityweb file, and then my feature works (specifically, I made some changes so that I can use the camera on iOS safari, which is not currently supported).
I want to do something similar to what’s described in this thread, but I want it to work in non-development builds as well:
So let’s say I want to make a change to “_JS_WebCamVideo_Start”.
I had GUESSED that I’d be able to modify, within my Unity installation, Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/lib/UnityNativeJs/UnityNative.js. But that didn’t do anything (I deleted the file and I could still build fine, even after deleting temp files. That confuses me, I’m not sure why this file is there then…)
My hope was that I could modify that file, and then, when I’m doing a non-development build, cross my fingers that Unity would gzip my changes to that file automatically. Wishful thinking perhaps!
First, what didn’t work. I tried taking the framework.unityweb file (attempted with both gzip and brotli), decompressing it (that worked), then recompressing it. Just to see if I could make my own compressed file. I couldn’t quite get that working, perhaps there are specific compression settings or details in the header. So I ruled out being able to make my own compressed framework.unityweb file.
However, I did realize that I can mix-and-match. So, I could have an uncompressed framework.unityweb file, but I can still have gzip/brotli compression for the other unityweb files (which are bigger anyways). So, my process looks like:
-Build the game with no compression
-Build the game with my compression of choice
-Modify the uncompressed framework.unityweb file
-Replace the framework.unityweb file in the compressed build with my modified (uncompressed) one
-Voila, I can use that compressed build.
I’ll write some scripts to automate this build process now. However, if there is a way to change Unity’s javascript templates outright instead of this roundabout approach, I’m all ears!
Ok worked it out! The particular file I was modifying was not the right one. There are a few javascript files in this directory with duplicated code, and I’m not sure what the one I was editing did (even deleting it didn’t change anything) (I put it back later just in case ).
However, I was able to modify other files and those changed did stick when I built. Files like… Unity Install/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/lib/WebCam.js Unity Install/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/prejs/MediaDevices.js
Thanks for your help, encouraged me to stick with it! I got thrown off scent by the duplicated code.