美文网首页
Unity导出webgl移动端弹窗提示移除

Unity导出webgl移动端弹窗提示移除

作者: ShawnWeasley | 来源:发表于2020-11-04 09:03 被阅读0次

适用于Unity2019.x
搜索compatibilityCheck第一个然后将,之前的内容替换如下即可:

compatibilityCheck: function (e, t, r) {
UnityLoader.SystemInfo.hasWebGL ? UnityLoader.SystemInfo.mobile ? t() : ["Edge", "Firefox", "Chrome", "Safari"].indexOf(UnityLoader.SystemInfo.browser) == -1 : t()
},

自动修改可以参考这篇:
http://www.manongjc.com/detail/16-qpgdhuxjyzrtwsv.html

在Editor下写一个脚本,脚本的具体内容如下:

using System;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

public class PostProcessBuild
{
    [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);
        Debug.Log(text.Contains("compatibilityCheck:function(e,t,r){UnityLoader.SystemInfo.hasWebGL?UnityLoader.SystemInfo.mobile?e.popup(\"Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.\",[{text:\"OK\",callback:t}]):[\"Edge\",\"Firefox\",\"Chrome\",\"Safari\"].indexOf(UnityLoader.SystemInfo.browser)==-1?e.popup(\"Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.\",[{text:\"OK\",callback:t}]):t():e.popup(\"Your browser does not support WebGL\",[{text:\"OK\",callback:r}])},"));
        text = text.Replace("compatibilityCheck:function(e,t,r){UnityLoader.SystemInfo.hasWebGL?UnityLoader.SystemInfo.mobile?e.popup(\"Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.\",[{text:\"OK\",callback:t}]):[\"Edge\",\"Firefox\",\"Chrome\",\"Safari\"].indexOf(UnityLoader.SystemInfo.browser)==-1?e.popup(\"Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.\",[{text:\"OK\",callback:t}]):t():e.popup(\"Your browser does not support WebGL\",[{text:\"OK\",callback:r}])},", "compatibilityCheck: function (e, t, r) {UnityLoader.SystemInfo.hasWebGL ? UnityLoader.SystemInfo.mobile ? t() : [\"Edge\", \"Firefox\", \"Chrome\", \"Safari\"].indexOf(UnityLoader.SystemInfo.browser) == -1 : t()},");
        File.WriteAllText(path, text);
        Debug.Log("OnPostProcessBuild");
    }
}

其中需要注意的是,如果Unity版本内容不同,需要替换的内容也不一样,如果Debug.Log这一行输出为false说明版本不一致导致这部分内容不一样,需要用户根据自己的版本去查找到UnityLoader.js中对应的代码进行替换,直到输出为true之后再替换Replace的前半部分内容(这部分因为复制过来自动排版增加了空格等问题调了很久)。

相关文章

网友评论

      本文标题:Unity导出webgl移动端弹窗提示移除

      本文链接:https://www.haomeiwen.com/subject/wvirvktx.html