2
\$\begingroup\$

I currently have a Unity game where the user can click on buttons to open up web pages, I use the following script on the button for this...

public void OpenURL(string url)
         {
             Application.OpenURL(url);
         }
     }

The URL is then put into the box that this script produces in the inspector and works perfectly.

However what I would now like to do is open the pages OFFLINE instead, so people without an internet connection can see the information. The way I envisage doing this is to save the web pages so they can be opened up locally in a browser offline. However I am stumped as to how to tell the button to open the relevant file and open it - is there a way of doing this? Maybe save the web page file in a local folder and point the button to that file?

This would be way easier that the only alternative I can think of - to save each web page as an image and have them open up as an image popup within the game as opposed to in the browser (there are a lot, so I would rather not have to do this!)

This is for PC Standalone only.

Any help would be greatly appreciated.

Thanks in advance!

\$\endgroup\$
  • \$\begingroup\$ Have you tried using file:// urls? I'm not positive of the formatting of them or if you can use relative pathnames but i'm sure you can construct a url to whatever file you need on disk if the file:// is allowed. \$\endgroup\$ – StarWeaver Mar 16 '16 at 17:39
  • \$\begingroup\$ Hi @StarWeaver thanks for your suggestion, I have given it a go and it does indeed open the offline files if I put the URL as the location on my computer. The only problem is getting it to work with relative addresses. Currently if I put... C:\Users\JAMES\Documents\Test Project for Maps\Links\Active_Management_Case_Study.html - it works. If I put the files in a folder called 'Links' in the build folder and use \\Links\Active_Management_Case_Study.html or file:\\Links\Active_Management_Case_Study.html nothing happens - any suggestions? It must be possible! \$\endgroup\$ – NIMBLE JIM Mar 16 '16 at 18:58
  • \$\begingroup\$ UPDATE - I can get it to open the file by placing the file directly in the build folder (in the same folder as the .exe file), and simply putting the filename in the URL field. However I need to have all the files in their own folder, otherwise the .exe file is going to get lost in amongst a sea of other files. If I put them in a folder called LINKS and put 'LINKS/filename' then nothing happens. \$\endgroup\$ – NIMBLE JIM Mar 16 '16 at 19:53
  • \$\begingroup\$ file://./dirname/filename maybe? Or use one of unity's functions to look up the base dir at runtime? \$\endgroup\$ – StarWeaver Mar 16 '16 at 20:06
  • \$\begingroup\$ @StarWeaver - problem solved, see below. Thanks for your help. \$\endgroup\$ – NIMBLE JIM Mar 16 '16 at 21:07
2
\$\begingroup\$

Problem Solved -

  • Add a folder into the build folder and put all the files you want to be opened in there

  • Change the Open URL script to say public void relativeURL(string url)

  • Now put 'dirname/filename' in the URL field

Hey presto - it now works!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.