赞
踩
方法名 | 简介 |
allowSceneActivation | 自动加载下个场景 |
isDone | 是否加载好场景 |
progress | 数值是从0到1 显示加载场景的进程 如果allowSceneActivation是false,则最高到0.9 |
-
- /// <summary>
- /// 异步加载场景的实现
- /// </summary>
- /// <returns></returns>
- protected virtual IEnumerator AsyncLoad(bool loadPanel)
- {
- AsyncOperation operation;
-
- //获取异步A程序走完 要进入的下个场景B.获取异步走完B场景 A(异步)-->B(场景)
- operation = SceneManager.LoadSceneAsync(sceneName);
-
- //判断是否开启异步
- if (loadPanel)
- {
-
- //查找加载异步A的对象
- GameObject panel = GameObject.Find(LoadPanelName);
- if (panel == null)
- {
- Debug.LogError($"{LoadPanelName}面板不存在");
- yield break;
- }
- //开启面板进度条
- panel.transform.PanelAppearance(true);
- // 设置下一个场景为false
- operation.allowSceneActivation = false;
- //获取面板面板进度条
- Slider slider = panel.GetComponentInChildren<Slider>();
- //进度条起始值为0
- slider.value = 0;
- float progressValue;
-
- // 是否加载好场景 true加载好 false未加载好(让走循环)
- while (!operation.isDone)
- {
- //加载场景进度小于1把当前值赋值。
- if (operation.progress < 0.9f)
- progressValue = operation.progress;
- else
- //加载场景进度 >1加载完成 赋值为1
- progressValue = 1.0f;
-
- //赋值给进度条
- slider.value = progressValue;
- //进度值大于1
- if (progressValue >= 0.9f)
- {
- slider.value = 1f;
- //设置下一个场景为true
- operation.allowSceneActivation = true;
- }
- yield return null;
- }
- //把当前进度条面板进行隐藏
- panel.transform.PanelAppearance(false);
- }
- else
- operation.allowSceneActivation = true;
- }
- }
-
-
-
- /// <summary>
- /// 控制一个面板的外观
- /// </summary>
- /// <param name="t"></param>
- /// <param name="on_off">显示则为true</param>
- /// <param name="active">是否为活动对象</param>
- public static void PanelAppearance(this Transform t, bool on_off, bool active = false)
- {
- CanvasGroup group = t.GetOrAddComponent<CanvasGroup>();
- int value = on_off == true ? 1 : 0;
-
- //射线检测
- group.blocksRaycasts = on_off;
- //交互
- group.interactable = on_off;
- //透明度
- group.alpha = value;
-
- t.gameObject.SetActive(on_off || active);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。