Unity WebGL 取消瀏覽器警告

lee_鹿遊原發表於2018-03-13

1.瀏覽器支援

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

 

2.可用方案

 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檔案,進行文字替換。

注:

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.

相關文章