using System.Collections; using UnityEngine; using BigSpace.XRCore.Base; using UnityEngine.SceneManagement; using BigSpace.XRCore.Scene; using System; using BigSpace.XRCore.Event; using BigSpace.Logic; public class SceneMgr : MonoSingleton { private Coroutine _currentCoroutine; // ��ǰ���ڽ��еij����л�Э�� private ISceneDataProvider _sceneDataProvider; // ���������ṩ�� private string _sceneName; public int nowSceneId = 0; //��ǰ��ʽ�ij���(�������м���ȳ���) public bool isCanMove = true;//�Ƿ�������ֱ��߶� public bool isTrigger = false; public bool handisactive = false; /// /// ��ʼ������������ /// /// ���������ṩ�ӿ� public void Initialize(ISceneDataProvider sceneDataProvider) { _sceneDataProvider = sceneDataProvider; } // Start is called before the first frame update void Start() { SceneManager.sceneLoaded += OnSceneLoaded; } private void OnSceneLoaded(Scene arg0, LoadSceneMode arg1) { if (_sceneName == arg0.name) { //Debug.Log("======================�����ڴ�"); Resources.UnloadUnusedAssets(); GC.Collect(); } } public void LoadScene(int sceneId) { if (_currentCoroutine != null) { Debug.LogWarning("A scene transition is already in progress."); return; } // ��ȡ�������� var loadingData = _sceneDataProvider.GetLoadingSceneData(sceneId); if (_sceneName != null && _sceneName == loadingData.SceneName) //ͬһ�������Ͳ���ת return; _sceneName = loadingData.SceneName; isTrigger = false; Debug.Log("��ʼ��ת����"+ _sceneName); GlobalEventMgr.Dispatch(GameEvent.EventSetHandMove, 1); _currentCoroutine = PersistenceCoroutineMgr.Instance.StartCoroutine(HandleSceneTransition(loadingData)); } public IEnumerator HandleSceneTransition(SceneData loadingData) { // ���� GlobalEventMgr.Dispatch(GameEvent.EventChangeScence); ChangSceneSphereMgr.Instance.ShowChangeSecne(true); yield return new WaitForSeconds(GameDataManage.Instance.outFadeTime); //Debug.Log("ok����===========================" + loadingData.id + "||" + loadingData.LoadingSceneName + "||" + loadingData.SceneName); if (!string.IsNullOrEmpty(loadingData.LoadingSceneName)) { yield return SceneManager.LoadSceneAsync(loadingData.LoadingSceneName); //��UI��� //if (loadingData.SceneName != "Waiting" && loadingData.SceneName != "Scene_07") //���ڵȴ����������� //{ // //Debug.Log("��˭:" + loadingData.id + "||" + loadingData.SceneName); // GlobalEventMgr.Dispatch(GameEvent.EventShowUI, loadingData.id % 10000); // yield return new WaitForSeconds(4f); //} } //Debug.Log("��ʼ��Ŀ�곡��.................."+ loadingData.SceneName); yield return SceneManager.LoadSceneAsync(loadingData.SceneName); _currentCoroutine = null; } }