当前位置:网站首页>Unity WebGL移动端去除警告

Unity WebGL移动端去除警告

2022-06-28 12:20:00 奇大可

修改Build\UnityLoader.js。
把下面代码替换成false

UnityLoader.SystemInfo.mobile //替换成false
["Edge", "Firefox", "Chrome", "Safari"].indexOf(UnityLoader.SystemInfo.browser) == -1 //替换成false

为了避免每次构建时都需要手动更改,使用PostBuildHandler脚本。Editor下创建PostBuildHandler脚本

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

public class PostBuildHandler
{
    [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);
    }
}

原网站

版权声明
本文为[奇大可]所创,转载请带上原文链接,感谢
https://blog.csdn.net/abcd5711664321/article/details/125403972