Unity异步加载进度条
先上代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
#region 佛祖保佑
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
佛祖保佑 永无BUG
*/
#endregion
public class AsyncLoadScene : MonoBehaviour
{
public static string NEXTSCENENAME = "ChooseLevelScene";
private Text text_loadProgress;
private RectTransform rectTransform_progressBar;
private AsyncOperation asyncLoadScene;
private float progressValue;
private void Start()
{
text_loadProgress = transform.Find("Text").GetComponent<Text>();
rectTransform_progressBar = transform.Find("Image").GetComponent<RectTransform>();
asyncLoadScene = SceneManager.LoadSceneAsync(NEXTSCENENAME);
asyncLoadScene.allowSceneActivation = false;
}
private void Update()
{
if(text_loadProgress && rectTransform_progressBar)
{
progressValue = Mathf.Lerp(progressValue, asyncLoadScene.progress / 0.9F, Time.deltaTime);
text_loadProgress.text = (progressValue * 100F).ToString("F0") + "%";
rectTransform_progressBar.sizeDelta = new Vector2(progressValue * 1280F, 85F);
if(rectTransform_progressBar.sizeDelta.x > 1275F) asyncLoadScene.allowSceneActivation = true;
}
}
}
接着如果你感到迷惑,请看如下游戏对象层级:

脚本挂在Panel对象上
那如何使用她呢?
public GameObject Prefab_loadScene;
private void Click_play(){
Instantiate(Prefab_loadScene);
}
//--------------或者请看如下----------------
public GameObject Prefab_loadScene;
private void Click_play(){
AsyncLoadScene.NEXTSCENENAME = "MainScene";
GameObject loadScener = Instantiate(Prefab_loadScene);
}
Unity异步加载进度条的更多相关文章
- Unity 异步加载进度条
public class View_LoadingScene : MonoBehaviour { //场景加载进度条对象 public GameObject loadingProgressBar; / ...
- Unity 异步加载 进度条
当我们进行游戏开发时,时常会进行场景切换,如果下个场景较大,切换时就会出现卡顿现象,甚至看起来像是"死机",非常影响用户体验,我们这时就可以运用异步加载,在界面上显示加载的进度条以 ...
- JS -- 异步加载进度条
今天在博客园问答里面看到博友问道怎么实现Ajax异步加载产生进度条. 很好奇就自己写了一个. 展现效果: 1) 当点击Load的时候,模拟执行异步加载. 浏览器被遮挡. 进度条出现. 实现思路: 1. ...
- unity WWW加载进度条
using UnityEngine; using System.Collections; public class testProgress : MonoBehaviour { void Start ...
- css3 linear-gradient实现页面加载进度条效果
最终效果图: html结构: <div> <p class="p1"> <span></span> < ...
- ajax页面加载进度条插件
下面两个都是youtube视频的加载进度条效果的ajax插件 一.官网:http://ricostacruz.com/nprogress/官网 github:https://github.com/rs ...
- pace.js – 加载进度条插件
这儿只是简单介绍一下这个插件pace.js. 在页面中引入Pace.js,页面就会自动监测你的请求(包括Ajax请求),在事件循环滞后,会在页面记录加载的状态以及进度情况.此插件的兼容性很好,可以兼容 ...
- 仿UC浏览器图片加载进度条
前几天用UC浏览器看新闻(无意中给UC打了广告),看到它的图片加载进度条,正好最近有时间,所以就自己写了一个. 效果图如下 进度条的底色和填充颜色都可以调整. 首先中间的笑脸作为一个整体,其实现代码如 ...
- 【Web前沿技术】纯 CSS3 打造的10个精美加载进度条动画
之前向大家介绍8款优秀的 jQuery 加载动画和进度条插件,今天这篇文章向大家推荐10个纯 CSS3 代码实现精美加载进度条动画效果的方案.加载动画和进度条在网站和 Web 应用中的使用非常流行,特 ...
随机推荐
- CSS3文本样式
目录 文本阴影 text-shadow 文本轮廓 text-outline 文本换行 word-break normal break-all keep-all word-wrap 新文本属性 text ...
- [bug] CDH 安装 哈希验证失败
分析 验证 parcel 文件的哈希值 和 sha 文件不一致:文件损坏,重新下载 和 sha 官网一致:配置httpd文件 参考 哈希值和官网不一致 https://blog.csdn.net/lv ...
- [web] 系统运维--单机
处理过程 浏览器发送请求经过网络到达web服务器 web服务器处理请求并响应数据 响应数据从web服务器发送到用户端 用户浏览器接收数据,本地计算渲染 指标 响应时间 吞吐量 响应时间 响应时间 = ...
- 如何用Python画一个圣诞树呢?
# ./sd.py * *** ***** ******* ********* |[root@bogon shengdan]# vim sd.py[root@bogon shengdan]# cat ...
- vim使用基础
vi/vim编辑器使用 前言 There is an old joke about a visitor to New York City asking a passerby for direction ...
- 《SystemVerilog验证-测试平台编写指南》学习 - 第3章 过程语句和子程序
<SystemVerilog验证-测试平台编写指南>学习 - 第3章 过程语句和子程序 3.1 过程语句 3.2 任务.函数以及void函数 3.3 任务和函数概述 3.4 子程序参数 3 ...
- tar cf XXX.tar /tmp /var 日志保存
tar cf XXX.tar /tmp /var 检测tar tf XXX.tar /tmp /var
- linux rpm包解压
rpm2cpio xxx.rpm | cpio -div
- mysql3_pymysql
python数据库编程 1.pyshon数据库接口(python DB-API) 1.为开发人员提供的数据库应用编程接口 2.python支持的数据库服务软件 mysql,oracle,sql_ser ...
- MyBatis 各种参数传递方式
MyBatis参数传递方式 情况一:Mapper映射器接口方法参数只有一个且为基本类型 接口方法: public List<UserEntity> selectUserByAge(int ...