如何卸载 unity WebGL [英] How to Unload unity WebGL

查看:100
本文介绍了如何卸载 unity WebGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 unity webGL 构建,这是在 javascript 中初始化/加载 unity webgl 的方法.

I am using unity webGL build and this is the way to initalize/load unity webgl in javascript.

 var gameInstance = UnityLoader.instantiate("gameContainer", "Build/WebGLDemo.json", {onProgress: UnityProgress});

但是没有办法卸载webgl.我可以删除画布标签,但问题是内存中保留了一些未被垃圾收集的资源.另外当我尝试删除

but there is no way to unload the webgl. I can remove the canvas tag but the problem is that some resources are remains in the memory which are not garbage collected. additionally when i try to remove

function DeleteGame(){
            console.log("remove game");
            document.getElementById("gameContainer").remove();
            //gameInstance = null;
      }

然后我们得到了 furstum 错误

then we are getting furstum error

视锥外的屏幕位置(屏幕位置 0.000000、0.000000、0.000000) (相机矩形 0 0 0 0)

Screen position out of view frustum (screen pos 0.000000, 0.000000, 0.000000) (Camera rect 0 0 0 0)

有没有什么合适的方法可以卸载webgl?

Is there any proper way available to unload the webgl?

推荐答案

在 Unity 2019 beta 中,unity 提供了一个内置方法(C#/JavaScript)来卸载 Unity WebGL 和清理内存.

In Unity 2019 beta, unity provides a built-in method(C#/JavaScript) to unload Unity WebGL and cleanup memory.

  • C#:调用 Application.Quit()
  • JS:调用 unityInstance.Quit(callback)

您可以使用 C# 版本或 Javascript:

You can either use C# version or Javascript:

unityInstance.Quit(function() {
    console.log("done!");
});
unityInstance = null;

有关详细信息,请查看 unity 论坛unity bug.

For more details check unity Forums and unity bug.

我在 unity 2019.1.0 beta 中使用过这个功能,但我不确定它是否会清理内存,但它肯定会关闭单元 webgl 应用程序.

这篇关于如何卸载 unity WebGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆