/// <summary> /// 异步加载指定的场景名称 /// </summary> /// <param name="sceneFileName">场景资源名称(其实是路径带扩展名)</param> /// <param name="begin">开始加载事件</param> /// <param name="failed">失败事件</param> /// <param name="loading">进度事件</param> /// <param name="finish">完成事件</param> /// <returns></returns> static bool LoadOTALevelAsyncImpl(string sceneFileName, SceneRootEntry.Begin begin, SceneRootEntry.Failed failed, SceneRootEntry.Loading loading, SceneRootEntry.Finished finish) { EB.Debug.Log("LoadOTALevelAsyncImpl=====>"); if (!m_SceneRootDict.ContainsKey(sceneFileName)) { m_SceneRootDict.Add(sceneFileName, new SceneRootEntry(sceneFileName)); } SceneRootEntry entry = null; m_SceneRootDict.TryGetValue(sceneFileName, out entry); if (entry != null) { int length = sceneFileName.IndexOf('.'); length = (length >= 0 ? length : sceneFileName.Length); //场景名称 string levelName = sceneFileName.Substring(0, length); string sceneUrl = GameEngine.Instance.OtaServer + "/" + entry.m_Path; entry.LoadOTALevelAsync(levelName, sceneUrl, begin, failed, loading, finish); return(true); } EB.Debug.LogError("加载场景生成错误_[SceneLoadManager]LoadOTALevelAsync: There is no definition of level [{0}]. ", sceneFileName); return(false); }
/// <summary> /// 异步加载场景 /// </summary> /// <param name="levelName"></param> /// <param name="levelPath"></param> /// <param name="begin"></param> /// <param name="failed"></param> /// <param name="loading"></param> /// <param name="finish"></param> public void LoadOTALevelAsync(string levelName, string levelPath, SceneRootEntry.Begin begin, SceneRootEntry.Failed failed, SceneRootEntry.Loading loading, SceneRootEntry.Finished finish) { if (m_RootEntry != null && m_RootEntry.m_Path == levelPath) { m_CurrentLevelName = levelName; m_CurrentLevelPath = levelPath; m_OnFinished = finish; HandleFinished(m_RootEntry); } else { InitLoad(); m_CurrentLevelName = levelName; m_CurrentLevelPath = levelPath; m_OnFinished = finish; m_RootEntry = new SceneRootEntry(levelPath); string sceneUrl = GameEngine.Instance.OtaServer + "/" + m_RootEntry.m_Path; m_RootEntry.LoadOTALevelAsync(levelName, sceneUrl, begin, failed, loading, HandleFinished); } }
/// <summary> /// 异步加载场景 /// </summary> /// <param name="stateName">状态名称</param> /// <param name="begin">开始加载事件</param> /// <param name="failed">失败事件</param> /// <param name="loading">进度事件</param> /// <param name="finish">完成事件</param> public static void LoadOTALevelGroupAsync(string stateName, SceneRootEntry.Begin begin, SceneRootEntry.Failed failed, SceneRootEntry.Loading loading, SceneRootEntry.Finished finish) { //要加载的资源数据列表 List <string> toLoad = new List <string>(); //要卸载的资源路径列表 List <string> toUnload = new List <string>(); SceneLoadConfig config = GetSceneLoadConfig(stateName); if (config != null && config.Load != null) { m_CurrentStateName = stateName; // find all the scenes to be loaded for (int i = 0; i < config.Load.Length; ++i) { toLoad.Add(config.Load[i]); } // find all the scenes to be unloaded for (int i = 0; i < m_ScenesLoaded.Count; ++i) { string sceneName = m_ScenesLoaded[i]; bool found = false; for (int j = 0; j < toLoad.Count; ++j) { if (sceneName == toLoad[j]) { found = true; break; } } if (!found) { toUnload.Add(sceneName); } } // unload all the scenes for (int i = 0; i < toUnload.Count; ++i) { DestroyLevel(toUnload[i]); } // hide all the scenes HideAll(); // load all the scenes for (int i = 0; i < toLoad.Count; ++i) { if (config.Show == toLoad[i]) { m_CurrentSceneName = config.Show; LoadOTALevelAsyncImpl(toLoad[i], begin, failed, loading, finish); } else { LoadOTALevelAsyncImpl(toLoad[i], null, null, null, BackLevelLoadFinished); } } m_ScenesLoaded = toLoad; //================================================================================ string json = GM.JSON.ToJson(toLoad); Hashtable cache = Johny.HashtablePool.Claim(); Hashtable content = Johny.HashtablePool.Claim(); content["Content"] = json; cache["SceneLoad"] = content; DataLookupsCache.Instance.CacheData(cache); Johny.HashtablePool.Release(cache); cache = null; //================================================================================ } else { EB.Debug.LogError("[SceneLoadManager]LoadOTALevelGroupAsync: CAN NOT find scene load config file for {0}.", stateName); } }