c# - 如何卸载统一的 WebGL
问题描述
我正在使用统一 webGL 构建,这是在 javascript 中初始化/加载统一 webgl 的方法。
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/WebGLDemo.json", {onProgress: UnityProgress});
但是没有办法卸载webgl。我可以删除画布标签,但问题是内存中保留了一些没有被垃圾收集的资源。另外,当我尝试删除
function DeleteGame(){
console.log("remove game");
document.getElementById("gameContainer").remove();
//gameInstance = null;
}
然后我们得到了 furstum 错误
视锥体之外的屏幕位置(屏幕位置 0.000000、0.000000、0.000000)(相机矩形 0 0 0 0)
有什么合适的方法可以卸载 webgl 吗?
解决方案
在 Unity 2019 beta 中,unity 提供了一个内置方法(C#/JavaScript)来卸载Unity WebGL 和清理内存。
- C#:调用 Application.Quit()
- JS:调用 unityInstance.Quit(callback)
您可以使用 C# 版本或 Javascript:
unityInstance.Quit(function() {
console.log("done!");
});
unityInstance = null;
我在 unity 2019.1.0 beta 中使用过这个功能,但我不确定它是否会清理内存,但它肯定会关闭单元 webgl 应用程序。
推荐阅读
- google-cloud-platform - 如何配置图表来监控服务器的内存使用情况
- angular - 从 Angular 8 中的动态 ngmodel 获取数据
- python - 合并字典中的大数据帧时,reduce 的意外行为
- thingsboard - 如何在 Thingsboard 中通过 /api/auth/login 获取 JWT_TOKEN?
- python - 谷歌云函数:Python 和 CORS
- amazon-web-services - 无法在 aws lambda 函数中调用外部 api
- c# - 如何恢复包 Visual Studio 2017
- javascript - 从我自己的 WebHosting 服务器读取多个 JSON 文件并构建几个Html 中的结构以及 Javascript 中读取的信息
- java - 无法让 Jgrid 中的 JPanel 立即对更改做出反应
- python - 在 python 中结束一个线程(也使用回调)