Unity发布WebGL如何解决移动端警告的问题

答案是将UnityLoader.js中的UnityLoader.SystemInfo.mobile和["Edge", "Firefox", "Chrome", "Safari"].indexOf(UnityLoader.SystemInfo.browser) == -1替换成false。
----------------------------------------------------------------------------------------------------------------------------

那如何自动化呢?

那就需要用到PostProcessBuild后处理脚本了,需要放到Editor文件夹内,脚本内容如下:

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)
    {
        if (target != BuildTarget.WebGL)
            return;
        var path = Path.Combine(targetPath, "Build/UnityLoader.js");
        var text = File.ReadAllText(path);
        text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
        text = text.Replace("[\"Edge\", \"Firefox\", \"Chrome\", \"Safari\"].indexOf(UnityLoader.SystemInfo.browser) == -1", "false");
        File.WriteAllText(path, text);
    }

    //[PostProcessBuild]
    //public static void OnPostProcessBuild(BuildTarget target, string targetPath)
    //{
    //    if (target != BuildTarget.WebGL)
    //        return;
    //    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发布WebGL如何解决移动端警告的问题)