Unity Android:如何在缓存中预加载场景

时间:2018-04-24 10:08:33

标签: android unity3d

当我在Android手机上安装应用程序后第一次加载场景时,需要时间I.e.几秒钟。此后所有场景加载速度非常快。我假设更快的加载时间是因为场景是从缓存加载的。 那么我怎样才能预加载缓存中的所有场景或至少重载#39;场景,以便他们第一次快速加载?

感谢。

1 个答案:

答案 0 :(得分:1)

简短的回答是你不能,第一次你的应用程序运行它会创建its own cache,这需要时间,但你可以创建一个加载屏幕并异步加载你的场景,有很多教程关于该

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Example : MonoBehaviour
{
    void Update()
    {
        //Press the space key to start coroutine
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //Use a coroutine to load the Scene in the background
            StartCoroutine(LoadYourAsyncScene());
        }
    }

    IEnumerator LoadYourAsyncScene()
    {
        // The Application loads the Scene in the background at the same time as the current Scene.
        //This is particularly good for creating loading screens. You could also load the Scene by build //number.
        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene2");

        //Wait until the last operation fully loads to return anything
        while (!asyncLoad.isDone)
        {
            yield return null;
        }
    }
}

http://blog.teamtreehouse.com/make-loading-screen-unity

https://www.youtube.com/watch?v=YMj2qPq9CP8

https://en.wikipedia.org/wiki/Dalvik_%28software%29