private void Awake( ) { _instatnce = this; _cache = AsyncLoaderCache.GetInstance( ); GameLogger.GetInstance( ).Trace("Unity:AsyncSceneLoader Awake"); // 通知:一个新场景开始加载了 EventDispatcher.GetInstance( ).Broadcasting(eEventType.AsyncLoaderScene); }
public void Update() { switch (_state) { case ReadyToLoadStateType.Init1: { if (!AssetBundleMgr.GetInstance().IsInited()) { break; } UiMgr.GetInstance().Init(); _state = ReadyToLoadStateType.Init2; break; } case ReadyToLoadStateType.Init2: { if (!UiMgr.GetInstance().IsInited()) { break; } _state = ReadyToLoadStateType.LoadScene; break; } case ReadyToLoadStateType.LoadScene: { // 初始化加载,下面二行可以优化成加载类 GameMain.GetInstance().Init(); // 设置 加载场景需要加载的数据 AsyncLoaderCache cache = AsyncLoaderCache.GetInstance(); cache.Loaders.Clear(); AsyncLoaderScene ssloader = new AsyncLoaderScene(AsyncLoader.SceneLoginAbPath, AsyncLoader.SceneLoginName, AsyncLoader.SceneLoginMapId); cache.Loaders.Add(ssloader); //AsyncLoaderTest testLoader = new AsyncLoaderTest( ); //cache.Loaders.Add( testLoader ); // 准备开始游戏了,加载“加载场景” SceneManager.LoadScene(AsyncLoader.SceneLoader); _state = ReadyToLoadStateType.Ok; break; } case ReadyToLoadStateType.Ok: break; } }
void OnSceneLoaded(Scene scene, LoadSceneMode mode) { Debug.Log("OnSceneLoaded: " + scene.name + " LoadSceneMode:" + mode); // AsyncLoaderScene if (scene.name.Equals(AsyncLoader.SceneLoader)) { var scrpts = Camera.main.gameObject.GetComponent <AsyncLoader>(); if (scrpts == null) { Camera.main.gameObject.AddComponent <AsyncLoader>(); } return; } _isLoadedMap = true; int mapId = AsyncLoaderCache.GetInstance().GetMapId(); if (mapId <= 0) { return; } _currentWorld = new World(ResourceAll.GetInstance().MapMgr.GetReference(mapId)); // 触发一个场景加载完毕的事件 EventDispatcher.GetInstance().Broadcasting <int>(eEventType.SceneLoadCompleted, mapId); // 初始化角色位置 if (_mainPlayer != null && Camera.main.gameObject != null) { // 增加一个相机跟随组件 CameraFollowBehaviour cTrack = Camera.main.gameObject.GetComponent <CameraFollowBehaviour>(); if (cTrack == null) { cTrack = Camera.main.gameObject.AddComponent <CameraFollowBehaviour>(); } if (_mainPlayer.GetGameObject() != null) { cTrack.Target = _mainPlayer.GetGameObject().GetComponent <Transform>(); } } // 场景加载完成之后,处理缓存的协议 HandlerCacheMsg(); }
public void LoadScene(string sceneAbPath, string sceneResName, int mapId) { // 通知,有新的场景需要加载了 EventDispatcher.GetInstance().Broadcasting(eEventType.SceneLoadStart); // 设置 加载场景需要加载的数据 AsyncLoaderCache cache = AsyncLoaderCache.GetInstance(); cache.Loaders.Clear(); AsyncLoaderScene ssloader = new AsyncLoaderScene(sceneAbPath, sceneResName, mapId); cache.Loaders.Add(ssloader); // 加载“加载场景” _isLoadedMap = false; SceneManager.LoadScene(AsyncLoader.SceneLoader); }