Last active
September 20, 2019 12:15
-
-
Save jfranmora/5c9992a66a0a0b95d312bb1369908fe1 to your computer and use it in GitHub Desktop.
PostBuildAction to Remove Mobile Warning in WebGL builds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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