[WebGL] 모바일 미지원 알림 제거 Unity 2019.4 이하
2022.02.09 추가
Unity 2020.1 이후 UnityLoader.js 에서 mobile warning 관련 코드가 사라지고
index.html 부분에서 처리하고 있어 해당부분을 삭제하는것으로 간단하게 해결된다.
2020.1 미만 버전에서만 대응 된 코드
아래 파일을
Assets/Editor/RemoveMobileSupportWarningWebBuild.cs 위치시킨다
아래 출처 참고
출처
https://gist.github.com/JohannesDeml/f551b1e60c59e8472c3e843014d7bd10
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemoveMobileSupportWarningWebBuild.cs">
// Copyright (c) 2021 Johannes Deml. All rights reserved.
// </copyright>
// <author>
// Johannes Deml
// public@deml.io
// </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."
/// </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
-- 기존 내용 --
유니티 webGL 빌드 후 모바일 디바이스로 접속시 아래와 같은 경고창을 볼 수 있다
Please note that Unity WebGL is not currently supported on mobiles.
Build/UnityLoader.js 를 안쪽에 모바일 디바이스 체크 부분을 수정해 주면 제거가 가능하다
빌드 때 마다 수동으로 수정을 하기는 힘드니 PostProcessBuild 콜백을 사용하여 빌드 후 해당 부분을 수정하도록 할 수있다.
아래 스크립트를 Assets > Editor 폴더에 넣어주면 간단하게 사용 가능하다
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
public class PostBuildAction
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
{
var path = Path.Combine(targetPath, "Build/UnityLoader.js");
var text = File.ReadAllText(path);
text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
File.WriteAllText(path, text);
}
}
참조 :
docs.unity3d.com/kr/2018.4/Manual/webgl-browsercompatibility.html
answers.unity.com/questions/1339261/unity-webgl-disable-mobile-warning.html