- Home /
Building game rewrites web.html page
I wanted to make my game open url page but in separate tab instead of the same window as my web build, so I made a function that does that by using Application.ExternalCall () function in unity.
Though the code works and the page is oppened in new tab, when I build my game, web.html page is rewriten from scratch using some default code template, i.e my code disappears.
Is there a way how to prevent this from happening or is there a place where I can edit what is generated by default in the web.html page?
Answer by spinnerbox · Dec 22, 2015 at 01:52 PM
You can define a web page to serve as a template for your web build in future. Here is the page where I found this info: http://docs.unity3d.com/Manual/UsingWebPlayertemplates.html
Create a folder called WebPlayerTemplates in your assets folder and then create another folder which will hold all files about the specific template. You can have multiple web templates and once you restart your Unity and reload your project, the templates will appear in Build Settings -> Player Settings -> Web Player.
The template must have index.html page and you can create thumbnail.png, 128x128 to serve as image in the templates section in Unity.
Was about to delete the question but it is useful so... :)
Answer by phil_me_up · Dec 22, 2015 at 01:42 PM
I've not done this for web games, but I would have thought you could make a PostProcess script that would open the html file and replace the contents.
Examples: http://docs.unity3d.com/ScriptReference/Callbacks.PostProcessBuildAttribute.html Note it's the [PostProcessBuild(x)] attribute that actually tells this to run once the build has completed. x should be replaced by the order you want this to run (so something where x=1 will run before something with x=200)
Here's a pretty together sample (sorry for errors if there are any, it's off the top of my head)
public static class cChangeSomething {
[PostProcessBuild(200)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
ChangeSomething (path);
}
public static void ChangeSomething(string path)
{
string fullPath = Path.Combine(path, Path.Combine(Path.Combine("Folder1", "Folder2"), "myfile.html"));
string data = Load (fullPath);
string wholeStatement = "This is the text you want to insert";
data = Regex.Replace (data, @"This is the text you want to replace", wholeStatement);
Save (fullPath, data);
}
}
Good point. I might use this for more advanced builds in future. However after a simple search about web.html and unity I found this page: http://docs.unity3d.com/$$anonymous$$anual/UsingWebPlayertemplates.html :)
That looks like a much nicer solution! Wasn't aware this existed but I'll keep it in $$anonymous$$d if I ever build for web.
Your answer
