/// <summary> /// 开始加载下一个场景 /// </summary> /// <param name="scene"></param> /// <param name="res"></param> public void StartLoadScene(GameResource.SceneName scene, List <LoadResourceModel> res, CallBack loadcall = null) { MaxResourceProgressValue = 100; //重置进度条显示 ProgressSilder.value = 0; //重置进度显示 ProgressText.text = "正在加载中... 0%"; //重置资源加载值 ResProgressValue = 0; //重置资源加载进度值 LoadResourceNumber = 0; //重置场景加载进度值 SceneProgressValue = 0; //重置资源加载显示进度 ResProgress = 0; //开始加载场景 IsStartLoading = true; switch (scene) { case GameResource.SceneName.MAIN: MaxResourceProgressValue = 0; break; default: ProgressGameObject.SetActive(true); break; } StartCoroutine(LoadScene(scene, res, loadcall)); }
/// <summary> /// 加载场景 /// </summary> /// <param name="scene"></param> /// <returns></returns> IEnumerator LoadScene(GameResource.SceneName scene, List <LoadResourceModel> list, CallBack loadcall) { //展示用的进度 int displaypro = 0; //实际的进度 int topro = 0; //开始加载下一个场景 async = SceneManager.LoadSceneAsync(GameData.Instance.SceneName[scene]); //暂时不进去下一个场景 async.allowSceneActivation = false; //在加载进度不足90%时,进行进度条缓动动画 while (async.progress < 0.9f) { topro = (int)(async.progress * 100f); //如果我们的显示进度尚未达到实际进度时,每帧增加百分之一 while (displaypro < topro) { displaypro++; SceneProgressValue = displaypro / 2; yield return(new WaitForFixedUpdate()); } } //加载最后一段进度 topro = 100; while (displaypro < topro) { displaypro++; SceneProgressValue = displaypro / 2; yield return(new WaitForFixedUpdate()); } //加载资源 LoadResource(list); displaypro = 0; //如果我们的显示进度尚未达到实际进度时,每帧增加百分之一 while (ResProgressValue <= 100 && displaypro < MaxResourceProgressValue) { displaypro++; ResProgress = displaypro / 2; yield return(new WaitForFixedUpdate()); } //全部加载完毕后,进入下一个场景 async.allowSceneActivation = true; //等待场景真正加载完毕 while (!async.isDone) { yield return(new WaitForFixedUpdate()); } IsStartLoading = false; //全部加载完毕后,执行回调 if (loadcall != null) { loadcall(); } //将加载页面隐藏 ProgressGameObject.SetActive(false); }
IEnumerator LoadScene(GameResource.SceneName scene, List <LoadResourceModel> resList, AsyncCallback loadCallback = null) { //显示用的进度 int displaypro = 0; //实际的进度 int topro = 0; //开始加载下一个场景 mAsyncOperation = SceneManager.LoadSceneAsync(GameData.Instance.SceneNameDict[scene]); mAsyncOperation.allowSceneActivation = false; //进度不足90时,播放缓动动画 while (mAsyncOperation.progress < 0.9f) { //如果我们显示的进度未到实际的进度,就增加显示的进度 topro = (int)(mAsyncOperation.progress * 100); while (displaypro < topro) { displaypro += 2; mScenePogrsValue = displaypro / 2; yield return(new WaitForFixedUpdate()); } } //加载最后一段进度,加载资源 topro = 100; while (displaypro < topro) { displaypro += 2; mScenePogrsValue = displaypro / 2; yield return(new WaitForFixedUpdate()); } //加载资源 LoadResource(resList); displaypro = 0; while (mResPogrsValue <= 100 && displaypro < mMaxResPogrsValue) { displaypro++; mResPogrsValue = displaypro / 2; yield return(new WaitForFixedUpdate()); } //全部加载完毕后,进入下一个场景 mAsyncOperation.allowSceneActivation = true; while (!mAsyncOperation.isDone) { yield return(new FixedUpdate()); } mIsStartLoading = false; //全部加载完毕后,执行回调 if (loadCallback != null) { loadCallback(); } //将加载页面隐藏 mPogresGO.gameObject.SetActive(false); }
/// <summary> /// 开始加载下一个场景 /// </summary> /// <param name="scene"></param> /// <param name="loadResourceModels"></param> public void StartLoadScene(GameResource.SceneName scene, List <LoadResourceModel> loadResourceModels, AsyncCallback loadCallback = null) { mPogrsSlider.value = 0; mPogrsText.text = "正在加载中...0%"; mLoadResNumber = 0; mResPogrsValue = 0; mScenePogrsValue = 0; //开始加载 mIsStartLoading = true; mPogresGO.gameObject.SetActive(true); StartCoroutine(LoadScene(scene, loadResourceModels, loadCallback)); }
/// <summary> /// 加载场景 /// </summary> /// <param name="tag"></param> public void LoadScene(GameResource.SceneName tag) { //如果当前场景名称和要加载的场景名称一致,则直接返回 if (GameData.Instance.GameLevelName == GameData.Instance.SceneName[tag]) { return; } //要加载的资源 List <LoadResourceModel> rModel = new List <LoadResourceModel>(); //加载完成后的回调 LoadManager.CallBack call = null; switch (tag) { case GameResource.SceneName.LOGO: { LoadResourceModel rM = new LoadResourceModel(); rM.type = GameResource.ResourceType.PREFAB; rM.path = GameResource.UIResourcePath + GameData.Instance.CanvasName[GameResource.CanvasTag.CANVASLOGO]; rModel.Add(rM); call = delegate() { //场景是空白场景,UI或其他资源为场景加载后进行实例化生成,添加到本场景 GameObject go = GameApp.Instance.ResourcesManagerScript.LoadInstantiateGameObject(rM.path, null, Vector3.zero); //UI和代码同样也是分离的,方便的代码热更新 go.AddComponent <UI_Logo>(); }; } break; case GameResource.SceneName.LOGIN: { LoadResourceModel rM = new LoadResourceModel(); rM.type = GameResource.ResourceType.PREFAB; rM.path = GameResource.UIResourcePath + GameData.Instance.CanvasName[GameResource.CanvasTag.CANVASLOGIN]; rModel.Add(rM); call = delegate() { //场景是空白场景,UI或其他资源为场景加载后进行实例化生成,添加到本场景 GameObject go = GameApp.Instance.ResourcesManagerScript.LoadInstantiateGameObject(rM.path, null, Vector3.zero); //UI和代码同样也是分离的,方便的代码热更新 go.AddComponent <UI_Login>(); }; } break; case GameResource.SceneName.MAIN: { LoadResourceModel rM = new LoadResourceModel(); rM.type = GameResource.ResourceType.PREFAB; rM.path = GameResource.UIResourcePath + GameData.Instance.CanvasName[GameResource.CanvasTag.CANVASMAIN]; rModel.Add(rM); call = delegate() { //场景是空白场景,UI或其他资源为场景加载后进行实例化生成,添加到本场景 GameObject go = GameApp.Instance.ResourcesManagerScript.LoadInstantiateGameObject(rM.path, null, Vector3.zero); //UI和代码同样也是分离的,方便的代码热更新 go.AddComponent <UI_Main>(); }; } break; case GameResource.SceneName.BATTLE: { LoadResourceModel rM = new LoadResourceModel(); rM.type = GameResource.ResourceType.PREFAB; rM.path = GameResource.UIResourcePath + GameData.Instance.CanvasName[GameResource.CanvasTag.CANCASBATTLE]; rModel.Add(rM); LoadResourceModel rM1 = new LoadResourceModel(); rM1.type = GameResource.ResourceType.PREFAB; rM1.path = GameResource.UIResourcePath + GameData.Instance.SystemUI[GameResource.SystemUIType.UIFIGHT_TP]; rModel.Add(rM1); LoadResourceModel rM2 = new LoadResourceModel(); rM2.type = GameResource.ResourceType.PREFAB; rM2.path = GameResource.UIResourcePath + GameData.Instance.SystemUI[GameResource.SystemUIType.CARDOTHER_TP]; rModel.Add(rM2); call = delegate() { //场景是空白场景,UI或其他资源为场景加载后进行实例化生成,添加到本场景 GameObject go = GameApp.Instance.ResourcesManagerScript.LoadInstantiateGameObject(rM.path, null, Vector3.zero); //UI和代码同样也是分离的,方便的代码热更新 go.AddComponent <GameOther>(); }; } break; } //开始加载场景 GameApp.Instance.LoadMangerScript.StartLoadScene(tag, rModel, call); }
public void LoadScene(GameResource.SceneName tag) { //如果当前要加载的场景和当前的一致,就返回 if (GameData.Instance.GameLevelName == GameData.Instance.SceneNameDict[tag]) { return; } List <LoadResourceModel> resList = new List <LoadResourceModel>(); LoadMgr.AsyncCallback callback = null; switch (tag) { //Logo场景 case GameResource.SceneName.Logo: { LoadResourceModel model = new LoadResourceModel(GameResource.ResourceType.Prefab, GameResource.UIResourcePath + GameData.Instance.CanvasDict[GameResource.CanvasTag.LogoCanvas]); resList.Add(model); callback = delegate() { //Debug.Log(GameResource.UIResourcePath + GameData.Instance.CanvasDict[GameResource.CanvasTag.LogoCanvas]); GameObject go = GameApp.Instance.ResourceMngr.InstantiateGameObject( GameResource.UIResourcePath + GameData.Instance.CanvasDict[GameResource.CanvasTag.LogoCanvas], null, Vector3.zero); go.AddComponent <UI_Logo>(); }; break; } //登录场景 case GameResource.SceneName.Login: { LoadResourceModel model = new LoadResourceModel(GameResource.ResourceType.Prefab, GameResource.UIResourcePath + GameData.Instance.CanvasDict[GameResource.CanvasTag.LoginCanvas]); resList.Add(model); callback = delegate() { GameObject go = GameApp.Instance.ResourceMngr.InstantiateGameObject( GameResource.UIResourcePath + GameData.Instance.CanvasDict[GameResource.CanvasTag.LoginCanvas], null, Vector3.zero); go.AddComponent <UI_Login>(); }; break; } case GameResource.SceneName.Main: { LoadResourceModel model = new LoadResourceModel(GameResource.ResourceType.Prefab, GameResource.UIResourcePath + GameData.Instance.CanvasDict[GameResource.CanvasTag.MainCanvas]); resList.Add(model); callback = delegate() { GameObject go = GameApp.Instance.ResourceMngr.InstantiateGameObject( GameResource.UIResourcePath + GameData.Instance.CanvasDict[GameResource.CanvasTag.MainCanvas], null, Vector3.zero); go.AddComponent <UI_Main>(); }; break; } case GameResource.SceneName.Battle: break; } GameData.Instance.GameLevelName = GameData.Instance.SceneNameDict[tag]; GameApp.Instance.LoadMgr.StartLoadScene(tag, resList, callback); }