【问题标题】:Unity WebGL override compatibilityCheck callbackUnity WebGL 覆盖兼容性检查回调
【发布时间】:2019-05-14 02:05:20
【问题描述】:

我目前正在开发一个 Unity WebGL 项目,该项目仅支持 WebGL 2.0。 该项目不适用于WebGL 1.0

现在我想意识到,如果浏览器不支持WebGL 2.0,则会显示图像而不是 WebGL 上下文。

如果不支持 WebGL,UnityLoader.instantiate() 函数有一个回调函数。不幸的是,我的代码没有在这个函数中调用。

    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";
            }

提前致谢! 此致, 劳伦斯·特里彭

【问题讨论】:

    标签: javascript unity3d webgl unity-webgl


    【解决方案1】:

    你可以试试

    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";
                }
    
       ...
    

    【讨论】:

      猜你喜欢
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      • 2011-11-13
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多