javascript - Unity WebGL 覆盖兼容性检查回调
问题描述
我目前正在开发一个 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";
}
提前致谢!最好的问候,劳伦斯·特里彭
解决方案
你可以试试
const supportsWebGL2 = !!document.createElement('canvas').getContext('webgl2');
因此,也许将您的 WebGL 模板更改为类似
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";
}
...
推荐阅读
- react-native - 尝试在 react-native 中使用 Button 时出错
- python - 谁能帮我理解这个三角形类中的部分代码?
- php - 从 CSV 文件中删除行并自动生成新文件
- hibernate - 如何在Spring Data中实现一个包含两个相同类型实体列表的实体
- sql - 如何在 Postgresql 中按 DISTINCT user_ids 和 GROUP BY 日期的数量计算列的 AVG 值
- python - 读取csv文件有困难
- templates - 在 Kendo 模板中渲染 HTML
- ruby-on-rails - Rails 5 加入过滤器关联
- nginx - nginx.conf 忽略了 nginx-ingress 配置映射片段
- group-by - sas中每个不同观察的平均___?