在使用Unity3D 2018生成的H5,运行时可能会弹出以下几种警告信息:
A.Your browser does not support WebGL
B.Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.
C.Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.
为了能够方便的取消这些浏览器警告,可使用以下代码。将以下代码放在位于Assets/Editor/PostBuildActions.cs文件中
using System; using System.IO; using System.Text.RegularExpressions; using UnityEditor; using UnityEditor.Callbacks; public class PostBuildActions { [PostProcessBuild] public static void OnPostProcessBuild(BuildTarget target, string targetPath) { var path = Path.Combine(targetPath, "Build/UnityLoader.js"); var text = File.ReadAllText(path); text = Regex.Replace(text, @"compatibilityCheck:function\(e,t,r\)\{.+,Blobs:\{\},loadCode", "compatibilityCheck:function(e,t,r){t()},Blobs:{},loadCode"); File.WriteAllText(path, text); } }
这样Unity打包完成后,会自动替代UnityLoader.js文件中警告提示
补充:
在使用Unity 2019重新导出H5后,发现之前写的OnPostProcessBuild已经没有替换compatibilityCheck:function,估计是正则表达式已经有问题。为了能在Unity 2019中取消浏览器警告,重写了这部分代码:
using System; using System.IO; using System.Text.RegularExpressions; using UnityEditor; using UnityEditor.Callbacks; public class PostBuildActions { [PostProcessBuild] public static void OnPostProcessBuild(BuildTarget target, string targetPath) { var path = Path.Combine(targetPath, "Build/UnityLoader.js"); var text = File.ReadAllText(path); text = text.Replace("UnityLoader.SystemInfo.mobile", "false"); File.WriteAllText(path, text); } }
- 本文固定链接: http://jingyan.idoubi.net/1773.html
- 转载请注明: 游戏创作者大陆 于 逗分享开发经验 发表