场景加载

1.可以在A场景中某一物体的Awake方法中启动协程提前加载下一个需要用到的场景

    IEnumerator loadScence(string sceneName)
    {
        async = SceneManager.LoadSceneAsync(sceneName);
        async.allowSceneActivation = false;//使场景加载完而不切换。
        yield return null;
    }

在需要切换场景时再设置async.allowSceneActivation = true; 场景就能切换了
public void needToChange()
{
async.allowSceneActivation = true; 
}

2.当使用SceneManager.LoadSceneAsync ("Scenes")异步加载时,往往会制作一个加载场景来过渡,但是当你要加载的场景过大时,就连这个过度场景都会出现卡顿问题(进度条、场景跳转)。

//装载尽可能多的数据传输速率,因此帧将下降。
//加载时显示出良好的快速进度条。
Application.backgroundLoadingPriority = ThreadPriority.High ;

 

//加载数据速度非常慢,尽量不影响游戏性能的。
//在游戏进行时有很好的后台加载。
Application.backgroundLoadingPriority = ThreadPriority.Low ;

3.分帧加载,可以自定义场景中的加载优先级

public class fpsload : MonoBehaviour

{

List<string> InfoList; int InfoListIndex = 0;

void start()

{

StratCoroutine(GetFromInfoList() );

}

IEnumerator GetFromInfoList()

{

foreach(string item in InfoList)

{

InfoListIndex++; if(InfoListIndex % 5 == 0) //每一帧提取5条数据 Debug.Log("Load"); yield return null; //在下一帧执行 } }

}

4.动态加载策略

当加载一个很大的场景时,可以使用配置文件配置场景中对象的权重,在加载时只需要加载基础场景,再根据当前角色的位置和设备的性能动态加载和卸载权重较低的对象。

 

 

posted @ 2019-08-20 19:54  mc宇少  阅读(340)  评论(0编辑  收藏  举报