在同一场景中加载多个视频时,Unity App冻结 [英] Unity App freezes when loading Multiple Videos on same Scene

查看:244
本文介绍了在同一场景中加载多个视频时,Unity App冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从菜单导航到包含8个1分钟MP4视频的场景时,这些视频使用RawImage组件上的新VideoPlayer脚本播放.我正在使用Unity 5.6.0b11 beta版.

在我要导航的场景中,预制件将视频加载到列表缩略图中,之前我是在加载图像而不是视频,并且工作正常,现在在尝试加载视频时,它在Axon 7上冻结了38秒以上(4GB RAM)和One Plus 3(6 GB RAM)上的32秒,但在Unity Player本身上播放时完全没有滞后.

我用于VideoPlayer的脚本来自以下 StackOverflow问题.

button.onClick.AddListener(new UnityEngine.Events.UnityAction(() =>
{
   SceneManager.LoadSceneAsync("SceneSponsors");
   StartCoroutine(CloseMenu());
}));

有没有办法,我可以处理慢速加载场景,或者在应用程序启动时加载mainScene并在需要时进行导航时在后台预加载它们.

我看到了在某处 Resources.Load()也使它在Android设备上变慢,但是我已经通过删除所有我用来加载图像精灵的Resources.Load()进行了测试,但是问题仍然存在.

修改: 这是我的CloseMenu()函数,仅用于滑动和移动菜单面板. P.S该应用程序仅在加载该特定场景时冻结,并在其他场景中正常运行.

IEnumerator CloseMenu()
{
    if (IsOpen)
    {
        Vector3 pos = MainMenuWindow.transform.position;
        iTween.ColorUpdate(CloseArea, new Color(0, 0, 0, 0f), .6f);
        iTween.MoveTo(MainMenuWindow.gameObject, new Vector3(Screen.width, pos.y, pos.z), .6f);
        IsOpen = false;
        yield return new WaitForSeconds(.3f);
        CloseArea.transform.position = new Vector3(-240 * ScaleFact, CloseArea.transform.position.y, CloseArea.transform.position.z);
    }
}

编辑2 我正在使用脚本在RawImage上加载VideoPlayer.这是播放模式以及VideoPlayer 解决方案

对于我的问题.我必须对此视频教程在Unity中顺利播放视频的博客.

When navigating from menu to a Scene that contains 8, 1-minutes MP4 videos, that are played using new VideoPlayer script on RawImage component. I am using Unity 5.6.0b11 beta version.

In the scene that I am trying to navigate has prefabs that loads videos in list thumbnails, previously I was loading Images instead of Videos and it was working fine, now when trying to load video it freezes for than 38 seconds on Axon 7 (4GB RAM) and 32 seconds on One Plus 3 (6 GB RAM) but does not lags at all when playing on Unity Player itself.

Script I used for VideoPlayer is from this StackOverflow Question.

button.onClick.AddListener(new UnityEngine.Events.UnityAction(() =>
{
   SceneManager.LoadSceneAsync("SceneSponsors");
   StartCoroutine(CloseMenu());
}));

Is there a way, I can work around with the Slow Loading Scenes or pre-load them in Background when mainScene is loaded on the App start and navigate in need.

I saw somewhere Resources.Load() also makes it slow on Android Devices, but I've tested by removing all Resources.Load() which I was using to load image sprites but the problem was still there.

Edit: Here's my CloseMenu() functions it is only used to swipe and move the menu panel. P.S the App freezes only on loading that particular Scene, and works smoothly for other.

IEnumerator CloseMenu()
{
    if (IsOpen)
    {
        Vector3 pos = MainMenuWindow.transform.position;
        iTween.ColorUpdate(CloseArea, new Color(0, 0, 0, 0f), .6f);
        iTween.MoveTo(MainMenuWindow.gameObject, new Vector3(Screen.width, pos.y, pos.z), .6f);
        IsOpen = false;
        yield return new WaitForSeconds(.3f);
        CloseArea.transform.position = new Vector3(-240 * ScaleFact, CloseArea.transform.position.y, CloseArea.transform.position.z);
    }
}

Edit 2 I am loading VideoPlayer on RawImage using Script. Here's what RawImage looks like in Play mode along with VideoPlayer, and in inactive mode.

解决方案

For my case of problem. I had to make some changes on the VideoPlayer API Script I was using from this StackOverflow Question

In the script I was using from that link. The Co-routine was started inside the Start() function, that made the videos in 8 different prefab, to load at once even they were in pause mode.

So I added a new function PlayVideoOnClick() and attached it to the Click Event of the RawImage, so now the video will be loaded only if the RawImage is clicked.

Changed from

public void Start()
{
    Application.runInBackground = true;
    StartCoroutine(playVideo());

}

To

public void PlayVideoOnclick()
{
    Application.runInBackground = true;
    StartCoroutine(playVideo());

}

P.S: You can also see my YouTube Video Tutorial and Blog on Playing Videos smoothly in Unity.

这篇关于在同一场景中加载多个视频时,Unity App冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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