先上代码:

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异步加载进度条的更多相关文章

  1. Unity 异步加载进度条

    public class View_LoadingScene : MonoBehaviour { //场景加载进度条对象 public GameObject loadingProgressBar; / ...

  2. Unity 异步加载 进度条

    当我们进行游戏开发时,时常会进行场景切换,如果下个场景较大,切换时就会出现卡顿现象,甚至看起来像是"死机",非常影响用户体验,我们这时就可以运用异步加载,在界面上显示加载的进度条以 ...

  3. JS -- 异步加载进度条

    今天在博客园问答里面看到博友问道怎么实现Ajax异步加载产生进度条. 很好奇就自己写了一个. 展现效果: 1) 当点击Load的时候,模拟执行异步加载. 浏览器被遮挡. 进度条出现. 实现思路: 1. ...

  4. unity WWW加载进度条

    using UnityEngine; using System.Collections; public class testProgress : MonoBehaviour { void Start ...

  5. css3 linear-gradient实现页面加载进度条效果

    最终效果图: html结构: <div>    <p class="p1">        <span></span>    < ...

  6. ajax页面加载进度条插件

    下面两个都是youtube视频的加载进度条效果的ajax插件 一.官网:http://ricostacruz.com/nprogress/官网 github:https://github.com/rs ...

  7. pace.js – 加载进度条插件

    这儿只是简单介绍一下这个插件pace.js. 在页面中引入Pace.js,页面就会自动监测你的请求(包括Ajax请求),在事件循环滞后,会在页面记录加载的状态以及进度情况.此插件的兼容性很好,可以兼容 ...

  8. 仿UC浏览器图片加载进度条

    前几天用UC浏览器看新闻(无意中给UC打了广告),看到它的图片加载进度条,正好最近有时间,所以就自己写了一个. 效果图如下 进度条的底色和填充颜色都可以调整. 首先中间的笑脸作为一个整体,其实现代码如 ...

  9. 【Web前沿技术】纯 CSS3 打造的10个精美加载进度条动画

    之前向大家介绍8款优秀的 jQuery 加载动画和进度条插件,今天这篇文章向大家推荐10个纯 CSS3 代码实现精美加载进度条动画效果的方案.加载动画和进度条在网站和 Web 应用中的使用非常流行,特 ...

随机推荐

  1. queryset惰性与缓存

    https://blog.csdn.net/zhu6201976/article/details/83550461

  2. shell脚本常用语法详解

    逻辑控制 if 语法:注意空格 a=1b=2if [ $a == $b ]then    echo "a==b"elif [ $a -gt $b ]then    echo &qu ...

  3. 19 常用API

    API 什么是API? API (Application Programming Interface) :应用程序编程接口 简单来说:就是Java帮我们已经写好的一些方法,我们直接拿过来用就可以了 1 ...

  4. systemctl服务------字符和图像界面切换systemctl set-default multi-user.target systemctl isolate multi-user.target #当前立即进入字符模式 [root@room4pc09 桌面]# systemctl isolate graphical.target #当前立即进入图形模式

    查看服务运行状态 [root@room4pc09 桌面]# systemctl status crond #查看服务运行状态 ● crond.service - Command Scheduler L ...

  5. 【转】Spring_IOC学习

    原文地址:http://github.thinkingbar.com/spring/ 一.XML文件语法的知识点 对于XML没有提示的话,在Eclipse中搜索XML catalog设置.对于XML文 ...

  6. 在Linux服务器,搭建K8s服务【脚本篇】

    前言 好久没有写博客了,本文主要是对网上文章的总结篇,主要是将安装和运行代码做了一次真机实验,亲测可用.文章内包含的脚本和代码,多来自于网络,也有我自己的调整和配置,文章末尾对参考的文献做了列举,方便 ...

  7. 基于开源Tars的动态负载均衡实践

    一.背景 vivo 互联网领域的部分业务在微服务的实践过程当中基于很多综合因素的考虑选择了TARS微服务框架. 官方的描述是:TARS是一个支持多语言.内嵌服务治理功能,与Devops能很好协同的微服 ...

  8. 微信小程序在ios系统不兼容new Date('yyyy-mm-dd')

    微信小程序中使用new Date('2021-04-01 10:11:20')来转换时间在苹果手机不生效 兼容写法为new Date('2021/04/01 10:11:20')

  9. 第三方跨平台进程和系统监控库gopsutil

    gopsutil psutil是一个跨平台进程和系统监控的Python库,而gopsutil是其Go语言版本的实现.本文介绍了它的基本使用. Go语言部署简单.性能好的特点非常适合做一些诸如采集系统信 ...

  10. python基础知识笔记(二) (出现语法以及颜色问题)

    以下是在学习Python时需要尤其要注意的点: 1.程序中出现中文,运行的时候出现如下错误: SyntaxError: Non-UTF-8 code starting with '\xc1' 则是编码 ...