Skip to content

Instantly share code, notes, and snippets.

@Novack
Forked from JohannesDeml/README.md
Created January 5, 2021 14:47
Show Gist options
  • Save Novack/4cfbd2584b4411133dd38bf731dc0cd0 to your computer and use it in GitHub Desktop.
Save Novack/4cfbd2584b4411133dd38bf731dc0cd0 to your computer and use it in GitHub Desktop.
Remove Unity Mobile Notification Warning for WebGL builds

Remove warning

Unity has a warning when running a webgl build on mobile (iOS, Android). In order to remove it, just add this file to an editor folder.

Live example

To see live examples see Unity Web GL Loading Test

Logic

The script will run after the build has completed and replace the checks from all generated javascript files.

Support

  • Tested with Unity 2019.3, but should work with any version
  • Works with Name Files as Hashes, since it looks for all js files in the Build folder
  • Only runs when building for WebGL, so you can use it for a multiplatform project

Further Notes

  • Unity adds this note, since the builds oftentimes don't work for mobile, so oftentimes it does make sense to include the info.
  • You might need to empty your browser cache to get the new javascript file without any warnings
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemoveMobileSupportWarningWebBuild.cs" company="Supyrb">
// Copyright (c) 2020 Supyrb. All rights reserved.
// </copyright>
// <author>
// Johannes Deml
// [email protected]
// </author>
// --------------------------------------------------------------------------------------------------------------------
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace Supyrb
{
public class RemoveMobileSupportWarningWebBuild
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
{
if (target != BuildTarget.WebGL)
{
return;
}
var buildFolderPath = Path.Combine(targetPath, "Build");
var info = new DirectoryInfo(buildFolderPath);
var files = info.GetFiles("*.js");
for (int i = 0; i < files.Length; i++)
{
var file = files[i];
var filePath = file.FullName;
var text = File.ReadAllText(filePath);
text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
Debug.Log("Removing iOS warning from " + filePath);
File.WriteAllText(filePath, text);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment