更改页面时如何清理和卸载 Unity WebGL 画布 [英] How do I clean up and unload a Unity WebGL canvas when changing page

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

问题描述

在下载并运行 Unity WebGL 游戏后更改当前页面时,我的网络应用程序出现问题.

I've got a problem on my web application when I am changing the current page after downloading and running a Unity WebGL game.

事实上,我确信游戏正在运行,因为我不断听到玩家死亡时的声音.

In fact, I know for sure that the game is running because I continuously hear the sounds when my player is dying.

有没有办法在更改网页时删除所有上下文?这可能是一种内存泄漏吗?

Is there a way to delete all of the context when changing a web page? Could this be a kind of memory leak?

编辑 1:我的 web 应用程序是用 AngularJS/Material 完成的

Edit 1: My web application is done with AngularJS / Material

推荐答案

解决方案很简单:在 iframe 中加载 WebGL unity,这会沙箱化应用程序.

The solution is simple: load the WebGL unity in an iframe, this sandboxes the application.

当您使用完统一应用程序后,只需删除 iframe 的节点,例如:

When you're done with the unity app just remove the node of the iframe like:

var iframe=...;
iframe.parentNode.removeChild(iframe);

它和它的所有资源都应该立即卸载.

And it and all of it's resources should be instantly unloaded.

当您在 iframe 中时,您无法直接与 Unity 播放器通信,但您仍然可以使用 postMessage.

You can't communicate with the Unity player directly when you're in an iframe but you still can pass messages to and from it with postMessage.

这篇关于更改页面时如何清理和卸载 Unity WebGL 画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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