-
Notifications
You must be signed in to change notification settings - Fork 54
/
RemoveMobileSupportWarningWebBuild.cs
50 lines (46 loc) · 1.58 KB
/
RemoveMobileSupportWarningWebBuild.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemoveMobileSupportWarningWebBuild.cs">
// Copyright (c) 2021 Johannes Deml. All rights reserved.
// </copyright>
// <author>
// Johannes Deml
// </author>
// --------------------------------------------------------------------------------------------------------------------
#if !UNITY_2020_1_OR_NEWER //Not needed anymore in 2020 and above
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace Supyrb
{
/// <summary>
/// Removes a warning popup for mobile builds, that this platform might not be supported:
/// "Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway."
/// This warning only shows up for unity versions prior to 2020.1
/// </summary>
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 mobile warning from " + filePath);
File.WriteAllText(filePath, text);
}
}
}
}
#endif