Skip to content

Instantly share code, notes, and snippets.

@jfranmora
Last active September 20, 2019 12:15
Show Gist options
  • Save jfranmora/5c9992a66a0a0b95d312bb1369908fe1 to your computer and use it in GitHub Desktop.
Save jfranmora/5c9992a66a0a0b95d312bb1369908fe1 to your computer and use it in GitHub Desktop.
PostBuildAction to Remove Mobile Warning in WebGL builds
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
public class RemoveMobileWarningWebGL
{
private const string JS_EXTENSION = ".js";
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
{
if (target == BuildTarget.WebGL)
{
RemoveWebGLWarning(targetPath);
}
}
private static void RemoveWebGLWarning(string targetPath)
{
var filePath = FindWebGLJSAutogenerated(targetPath);
var text = File.ReadAllText(filePath);
text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
File.WriteAllText(filePath, text);
}
private static string FindWebGLJSAutogenerated(string targetPath)
{
var buildPath = Path.Combine(targetPath, "Build");
foreach (var filePath in Directory.GetFiles(buildPath))
{
if (IsJavascriptFile(filePath))
{
return filePath;
}
}
throw new System.Exception("Can't find Javascript file!");
}
private static bool IsJavascriptFile(string filePath)
{
return Path.GetExtension(filePath).ToLowerInvariant().Equals(JS_EXTENSION);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment