用栈来管理UI界面:SceneLoadManager
为了考虑切换场景的情况,所以还得有一个跳转场景的管理器。本来就算跟ViewManager无关,如果要做一个跳转场景的过场动画,那么应该也是要有这么一个SceneLoadManager的。切场景的时候先把过场动画加载进来,注意这个过场动画得是Don't Destroy的。然后开始异步加载场景,场景加载完成过后在退出过场动画。然后还可以执行一个回调函数,例如打开一个界面。
public class SceneLoadManager : MonoBehaviour {
public static SceneLoadManager Instance { get; private set; }
private AsyncOperation AsyncOpe;
void Awake()
{
Instance = this;
}
public void LoadSceneAsync(string sceneName, Action callBack)
{
ShowLoadingAnim();
StartCoroutine(LoadAsync(sceneName, callBack));
}
public void LoadSceneAsync(int sceneIndex,Action callBack)
{
ShowLoadingAnim();
StartCoroutine(LoadAsync(sceneIndex, callBack));
}
IEnumerator LoadAsync(string sceneName,Action callBack)
{
AsyncOpe = SceneManager.LoadSceneAsync(sceneName);
yield return AsyncOpe;
if(AsyncOpe.isDone)
{
OutLoadingAnim();
callBack();
AsyncOpe = null;
}
}
IEnumerator LoadAsync(int sceneIndex,Action callBack)
{
AsyncOpe = SceneManager.LoadSceneAsync(sceneIndex);
yield return AsyncOpe;
if(AsyncOpe.isDone)
{
OutLoadingAnim();
callBack();
AsyncOpe = null;
}
}
void ShowLoadingAnim()
{
//if (LoadingHandler.Instance!=null)
// LoadingHandler.Instance.Show();
}
void OutLoadingAnim()
{
//if (LoadingHandler.Instance!=null)
// LoadingHandler.Instance.Out();
}
public float getProgress()
{
return AsyncOpe.progress;
}
}
- 上一篇: 用栈来管理UI界面:IView
- 下一篇: UGUI:CenterOnChild