Unity笔记-场景管理器

SceneManager:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class SceneManager : ManagerBase<SceneManager>
{
public List<string> sceneList = new List<string>();
//当前场景
public int CurrentIndex=0;//当前场景
private System.Action<float> currentAction;
//当前加载场景对象
private AsyncOperation operation;
//加载
public void LoadScene(string sceneName,System.Action<float> action){
currentAction = action;
if(sceneList.Contains(sceneName)){
//更新场景索引
CurrentIndex = sceneList.IndexOf(sceneName);
//加载
operation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName,UnityEngine.SceneManagement.LoadSceneMode.Single);

}
}
void Update(){
if(operation !=null){
currentAction(opration.prograss);//加载百分比
if(operation.prograss>1){
opreation = null;
}
}

}
}