Unity WebGL 取消浏览器警告

1.浏览器支持

https://docs.unity3d.com/Manual/webgl-browsercompatibility.html

2.可用方案

 1  using System;
 2  using System.IO;
 3  using System.Text.RegularExpressions;
 4  using UnityEditor;
 5  using UnityEditor.Callbacks;
 6  
 7  public class PostBuildActions {
 8      [PostProcessBuild]
 9      public static void OnPostProcessBuild(BuildTarget target, string targetPath) {
10          var path = Path.Combine(targetPath, "Build/UnityLoader.js");
11          var text = File.ReadAllText(path);
12          text = Regex.Replace(text, @"compatibilityCheck:function\(e,t,r\)\{.+,Blobs:\{\},loadCode",
13              "compatibilityCheck:function(e,t,r){t()},Blobs:{},loadCode");
14          File.WriteAllText(path, text);
15      }
16  }

Unity打包完毕后,修改UnityLoader.js文件,进行文本替换。

注:

1. Unity Release模式导出有效,Debug模式文本内容不一致(可自行修改正则代码)

2. WebGL我使用的是Unity 2017.1版本 ,高版本暂时没测试有效性。

相关警告提示:

Your browser does not support WebGL
Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.
Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.
上一篇:在JavaScript / HTML5中显示3D模型


下一篇:WebGL / Javascript:具有多个对象的对象转换