- Home /
Deeplinking WebGL build (aka Flash's SWFAddress) ?
Hey!
I know non-webGL builds have some kind of deep linking implementation https://docs.unity3d.com/Manual/enabling-deep-linking.html
How about WebGL? Unless such plugin/functionality (even 3rd party) exists, ill have to do it myself.
I understand Flash had its own Javascript+Actionscript implementation to do it (and also PHP mirrored data model for SEO).
Answer by Bunny83 · Jan 19, 2021 at 03:50 PM
This doesn't make much sense ^^. First of all usual Deep linking in the context of websites is something different that deep linking in the context of mobile apps. In the second case it's about registrating a new URL scheme (in case of Unity the "unitydl" scheme) by the OS so when such an URL is encountered the OS will start a certain registrated application and pass the information in the URL to that application.
In the context of websites that doesn't really make much sense since web content is already hosted on a web server and only available through a link to the server where it's hosted. For example this is my parallel Mandelbrot Renderer hosted on github pages. My WebGL application does recognise custom properties in the URL and parses it at load. For example this one. So when opening the webgl application with this link it will automatically center on the given complex number and start rendering at the given zoom level.
If you want to do something similar my URLParameters singleton script is over here. I've found this old question where I explain the class a bit more in detail. Note that there's an old and a new version of the script. The old one used ExternalEval to directly execute JS code in the browser. Since that has been deprecated we have to use a seperate jslib plugin file. My URLParameters script will automatically extract the embedded jslib when you import the script in the editor. It does check the existance of the jslib every time the editor / project is loaded and if it's missing it will extract the file.
You can also use this class to set the hash / URL fragment from script. This is what my Mandelbrot renderer does every time you change the view / zoom.
I just realised that you probably are talking about normal "deep linking". As I essentially have explained you can use the URL fragment to dynamically update your content based on that. Keep in $$anonymous$$d when you actually change the URL (anything before the fragment "#") the browser will reload the page and your Unity WebGL content has to be reloaded as well.
If you want to the user to be able to click on a link on your webpage that has a different fragment or the user should be allowed to change the fragment in the URL manually, you can listen to the onhashchange callback of your browser in javascript and forward this callback to Unity through Send$$anonymous$$essage,
Note that it is not possible to register a new scheme for a website. What you could do is having a special "redirect link page" so when the user opens this special page, the page itself will look for other tabs / windows where your main content may run, communicate it's parameters to the main page and close itself. If no such tab / window exists it could simply redirect to the main page and load the actual webgl application that way. This would be kind of like mobile deep linking. However it depends on your specific needs and usecases.
Answer by _watcher_ · Jan 19, 2021 at 07:53 PM
Hot stuff!
Thank you @Bunny83, you are a godsend as always. Yes i ment the 'normal deep linking' with the hash fragment, as you explained in your second message. That's why a php mirror of the data model, for creating a crawlable content - but i think it might get blacklisted by googlul for ghosting. Either way, that's how SWFAddress did it.
The onhashchange callback is what i was looking for, cheers!
PS your Mandelbrot app reminds me of the good ol' uni days, i also wanted to recreate it in Unity once i got some time, but now i don't have to, i can simply dig into your code <3
Your answer
Follow this Question
Related Questions
How to open a Webgl unity game from a different html page? 1 Answer
Open WebGL link different from the domain i'm running my gam 0 Answers
Dynamic link url and text in WebGL build 2 Answers
WebGL build with SCORM 1.2 is not working in LMS 1 Answer
i found this error when loading WebGL build in chrome - 64 bit. 1 Answer