首页 技术 正文
技术 2022年11月7日
0 收藏 496 点赞 829 浏览 1810 个字

1、直接创建三个场景,其中第二个场景是用来显示进度条加载的界面,进度条用UISlider

2、这里提供两种方法,建议使用第一种,加载比较平缓

方法一:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;public class LoadingPags : MonoBehaviour
{ public UISlider progressBar; //进度条的引用
private string ScenceName="C"; //加载场景的名字
private float dtimer = ;
private float target = ; AsyncOperation op = null; private void Start()
{
Debug.Log("进入异步"); //op = SceneManager.LoadSceneAsync(ScenceName); //进入loadScene方法
//op.allowSceneActivation = false; progressBar.value = ; //弃用前将其进行初始化了
StartCoroutine(ProcessLoading());
} private void Update()
{
dtimer += Time.deltaTime;
progressBar.value = Mathf.Lerp(progressBar.value, target, dtimer * 0.2f);
//乘以的数值用来控制加载的速度,当新场景比较小的时候可以使用较小的值,有一定的效果,当场景加载较大的时候就不建议这么使用了
if(progressBar.value>=0.99f)
{
progressBar.value = ; //使其的值达到完整
op.allowSceneActivation = true; //为true 的时候才可以进行加载新的场景
} }
IEnumerator ProcessLoading()
{ op = SceneManager.LoadSceneAsync(ScenceName); //进入loadScene方法
op.allowSceneActivation = false; while (true) //死循环,使其在场景没有加载完成时就不退出了
{
target = op.progress;
if(target>=0.9f) //当场景加载了90%了
{
target = ;
yield break;
}
yield return ; }
}
}

第二种:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;public class Loadign : MonoBehaviour { public UISlider uislider;
private AsyncOperation asyn=null; public static string LoadingName; //声明一个静态的字符串变量俩保存要加载的场景名称
void Start ()
{
if(uislider)
{
//进度条丢失了
}
StartCoroutine(Loading());
} // Update is called once per frame
void Update ()
{ uislider.value = asyn.progress;
//Debug.Log(uislider.value);
//if (uislider.value>=0.8)
//{
// uislider.value = 1; // asyn.allowSceneActivation = true;
//} }
IEnumerator Loading()
{
asyn = SceneManager.LoadSceneAsync(); //加载第三个尝尽
asyn.allowSceneActivation = false;
//uislider.value = asyn.progress; //赋值
yield return asyn;
} //封装好的静态函数
public static void LoadNewScene(string value)
{
LoadingName = value;
SceneManager.LoadScene("Loadign");
}}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,903
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,427
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,244
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,057
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,687
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,726