using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
public class ScenesManager : BaseManager<ScenesManager>
{
/// <summary>
/// 同步加载
/// </summary>
/// <param name="name">场景名</param>
/// <param name="callback">回调</param>
public void LoadScene(string name, UnityAction callback)
{
SceneManager.LoadScene(name);
callback.Invoke();
}
/// <summary>
/// 异步加载
/// </summary>
/// <param name="name">场景名</param>
/// <param name="callback">回调</param>
public void LoadSceneAsync(string name, UnityAction callback)
{
MonoManager.GetInstance().StartCoroutine(ReallyLoadSceneAsync(name, callback));
}
private IEnumerator ReallyLoadSceneAsync(string name, UnityAction callback)
{
AsyncOperation ao = SceneManager.LoadSceneAsync(name);
//等待加载完
while (!ao.isDone)
{
//执行加载过程中的相关逻辑,例如进行加载进度显示
yield return ao.progress;
}
callback.Invoke();
}
}
Unity基础小框架(六):场景同步、异步加载模块
最新推荐文章于 2024-07-17 16:21:57 发布