Hey @jterry ,
I may have found some solution, everything seems fine but I didnt test too much Anyway, if you can benchmark this and share the results I would be thankful as i can
t do this right now.
1:
After compiling open the UnityLoader.js file
2: Find this:
loadCode(Math.fround?r:UnityLoader.Utils.optimizeMathFround(r)
and replace with this:
loadCode(r
Then you will need to edit the compiled asm code to remove the calls to the math.fround calls. In Unity 5.6.4 this reference is defined as var W=global.math.fround;
To remove all the references to it, i wrote a simple script to run in unity.
1 - Compile the webGL project as uncompressed (or if you want, you can compile as gzip and manually extract the code from the gzip file)
2 - Find the _code.unityweb file, open in an text editor, search for “math.fround” just to check if the definition is var W in your version too.
3 - Open any Unity Project. Create this script and attach to anything in the scene:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RemoveFround : MonoBehaviour
{
public TextAsset codeFile;
public string filename = "code.unityweb";
private void Start()
{
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder(codeFile.text);
for (int x = 1; x < strBuilder.Length - 1; x++)
{
if (strBuilder[x] == 'W')
{
if ((strBuilder[x - 1] == '?' || strBuilder[x - 1] == ':' || strBuilder[x - 1] == '~' || strBuilder[x - 1] == '=' || strBuilder[x - 1] == '-' || strBuilder[x - 1] == '+' || strBuilder[x - 1] == '*' || strBuilder[x - 1] == '/' || strBuilder[x - 1] == '&' || strBuilder[x - 1] == '|' || strBuilder[x - 1] == '<' || strBuilder[x - 1] == '>' || strBuilder[x - 1] == ')' || strBuilder[x - 1] == '(' || strBuilder[x - 1] == ';' || strBuilder[x - 1] == ',' || strBuilder[x - 1] == ' ') && strBuilder[x + 1] == '(')
{
strBuilder[x] = ' ';
}
}
}
string str = strBuilder.ToString();
System.IO.File.WriteAllText(Application.dataPath + "/" + filename, str);
}
}
Rename your code.unityweb file to code.txt, and import this file to the opened Unity Project.
Drag and drop the code.txt (an TextAsset) from project to the “codeFile” field in the inspector.
Set the filename that will be saved accordingly. Also note, that if in the definition for the Math.fround calls wasn`t W, you will need to edit this line:
if (strBuilder[x] == 'W')
After pressing play there will be a file in the path relative do dataPath with the given filename. This is the unity compiled code stripped from the Math.fround calls.
You can upload it uncompressed to your server, or manually gzip it. Just remember to use the correct filename in the unity Build .Json file
I tested this process in IE and everything ran fine, without extra lag as other solutions and without doing the “Optmizing” step
Also note that this process is sucetible to crashes, as the original definition var W=global.math.fround is still there, and if thera was an case that the replace code didn`t change IE will fail.
This can be changed changing the
var W=global.math.fround;
to
var W=function(a){return a;};
There will be no crashes if something failed, but there will be a overhead hard to find.