Unity WebGL removes mobile warnings

Modify Build \ UnityLoader.js.
Replace the following code with false

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

In order to avoid manual changes every time you build, use PostBuildHandler script.

using System;
using System.IO;
using UnityEditor;
 
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);
    }
}

Guess you like

Origin www.cnblogs.com/kingBook/p/12736380.html