Unity WebGL 覆盖 compatibilityCheck 回调
Unity WebGL override compatibilityCheck callback
我目前正在做一个 Unity WebGL 项目,它只支持 WebGL 2.0
。
该项目不适用于 WebGL 1.0
.
现在我想知道,如果浏览器不支持 WebGL 2.0
,将显示图像而不是 WebGL 上下文。
对于 UnityLoader.instantiate()
函数,如果不支持 WebGL,则有一个回调函数。不幸的是我的代码没有在这个函数中调用。
UnityLoader.instantiate("unityContainer", "Build/Build.json", {
compatibilityCheck: function(unityInstance, onsuccess, onerror) {
if (!UnityLoader.SystemInfo.hasWebGL) {
unityInstance.popup("Your browser does not support WebGL", [{text: "OK", callback: onerror}]);
document.getElementById("unityContainer").style.display = "none";
document.getElementById("fallbackHeader").style.display = "block";
}
提前致谢!
最好的祝福,
劳伦斯·特里彭
你可以试试
const supportsWebGL2 = !!document.createElement('canvas').getContext('webgl2');
所以也许 change your WebGL template 类似于
const supportsWebGL2 = !!document.createElement('canvas').getContext('webgl2');
if (!supportsWebGL2) {
// do something to display message
} else {
UnityLoader.instantiate("unityContainer", "Build/Build.json", {
compatibilityCheck: function(unityInstance, onsuccess, onerror) {
if (!UnityLoader.SystemInfo.hasWebGL) {
unityInstance.popup("Your browser does not support WebGL", [{text: "OK", callback: onerror}]);
document.getElementById("unityContainer").style.display = "none";
document.getElementById("fallbackHeader").style.display = "block";
}
...
我目前正在做一个 Unity WebGL 项目,它只支持 WebGL 2.0
。
该项目不适用于 WebGL 1.0
.
现在我想知道,如果浏览器不支持 WebGL 2.0
,将显示图像而不是 WebGL 上下文。
对于 UnityLoader.instantiate()
函数,如果不支持 WebGL,则有一个回调函数。不幸的是我的代码没有在这个函数中调用。
UnityLoader.instantiate("unityContainer", "Build/Build.json", {
compatibilityCheck: function(unityInstance, onsuccess, onerror) {
if (!UnityLoader.SystemInfo.hasWebGL) {
unityInstance.popup("Your browser does not support WebGL", [{text: "OK", callback: onerror}]);
document.getElementById("unityContainer").style.display = "none";
document.getElementById("fallbackHeader").style.display = "block";
}
提前致谢! 最好的祝福, 劳伦斯·特里彭
你可以试试
const supportsWebGL2 = !!document.createElement('canvas').getContext('webgl2');
所以也许 change your WebGL template 类似于
const supportsWebGL2 = !!document.createElement('canvas').getContext('webgl2');
if (!supportsWebGL2) {
// do something to display message
} else {
UnityLoader.instantiate("unityContainer", "Build/Build.json", {
compatibilityCheck: function(unityInstance, onsuccess, onerror) {
if (!UnityLoader.SystemInfo.hasWebGL) {
unityInstance.popup("Your browser does not support WebGL", [{text: "OK", callback: onerror}]);
document.getElementById("unityContainer").style.display = "none";
document.getElementById("fallbackHeader").style.display = "block";
}
...