先上代码:

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);
}

最新文章

  1. .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
  2. Session中放错误提示JSP上获取
  3. jquery 插件
  4. object-c 的ARC 问答/介绍
  5. Java 线程池的介绍以及工作原理
  6. java arrayCopy
  7. 【转】shell脚本调试(bash trap support bashdb )
  8. bzoj2938
  9. (转载)浅谈javascript的分号
  10. WebKit历史项管理的实现
  11. Java学习----你可以告诉对象该怎么做(方法中传参)
  12. Delphi——Window 消息 - 转载▼
  13. GetWindowRect和GetClientRect的区别详解
  14. 使用TensorFlow中的Batch Normalization
  15. Android -传统蓝牙通信聊天
  16. Django之基于iframe的ajax伪造
  17. [LeetCode] 832. Flipping an Image_Easy
  18. paypal对接
  19. 1001. 温度转换 (Standard IO)
  20. zoj 2976 Light Bulbs(暴力枚举)

热门文章

  1. 通过Cloudflare开启全站https
  2. gdb 调试,当发现程序退出,需要定位程序退出位置时。
  3. mysql不停库恢复
  4. Linux服务之nginx服务篇四(配置https协议访问)
  5. HTML html5 语义化标签
  6. 11.11 ntsysv:管理开机服务
  7. 三大主流开源硬件对比:Arduino vs Raspberry Pi vs BeagleBone
  8. 【python接口自动化】初识unittest框架
  9. 旷视MegEngine网络搭建
  10. CodeGen按钮循环