异步加载——进度条君(▰╹◡╹▰)

嗯...这是我几个月之前写的,没想到又翻出来用上了大笑

using UnityEngine;
using System.Collections;
using UnityEngine.UI;


public class Loading : MonoBehaviour
{
    AsyncOperation async;//
    public Slider slider;//进度条
    public Text percent;//百分比的显示
    public Text toolTip;//一些提示信息,装饰用的,可有可无吧
    //public Sprite[] bg;//背景图片
    //public Image loadingBG;
    string[] tip;//提示的数组
    public static string loadName;//要加载的场景的名字,用的时候先赋值给这个,然后再跳转到loading的这个场景
    public const string loadThis = "Loading";//进度条君所在的场景
    void Start()
    {
        //Debug.Log(bg.Length);
        //int count = Random.Range(0, bg.Length);
        //loadingBG.sprite = bg[count];//这里是做了一个进入场景随机播放一张图片的功能
        tip = new string[26];//26个颜文字(づ ̄3 ̄)づ╭❤~
        tip[0] = "(。・`ω´・)";
        tip[1] = "w(゚Д゚)w";
        tip[2] = "ヽ(✿゚▽゚)ノ";
        tip[3] = "(づ ̄3 ̄)づ╭❤~";
        tip[4] = "︿( ̄︶ ̄)︿";
        tip[5] = "Hi~ o(* ̄▽ ̄*)ブ";
        tip[6] = "~~( ﹁ ﹁ ) ~~~";
        tip[7] = "(ˉ▽ ̄~) 切~~";
        tip[8] = "✧(≖ ◡ ≖✿)";
        tip[9] = "ヾ( ̄▽ ̄)Bye~Bye~";
        tip[10] = "Ψ( ̄∀ ̄)Ψ";
        tip[11] = "X﹏X";
        tip[12] = "(๑¯◡¯๑)";
        tip[13] = "ლ(╹◡╹ლ)";
        tip[14] = "┻━┻ (ヽ(`Д ́)ノ( ┻━┻ ";
        tip[15] = "(๑•̀ω•́ ๑) 酱酱酱";
        tip[16] = "(σ゚∀゚)σ呦呦";
        tip[17] = "(o・_・)ノ”(ノ_<。)别哭啦";
        tip[18] = "=͟͟͞͞ =͟͟͞͞ ヘ( ´Д`)ノ 放我去死一死啊";
        tip[19] = "(ノ°ο°)ノ";
        tip[20] = "(▰╹◡╹▰)";
        tip[21] = "✧( ु•⌄• )◞◟( •⌄• ू )✧";
        tip[22] = "(っ´ω`)っ☂⊂(´ω`⊂ )";
        tip[23] = "ԅ( ˘ω˘ ԅ)";
        tip[24] = "( ·̀⊿·́)ง☎️110我要报警了!";
        tip[25] = "༼⍤ ᷇Θ̵̵̵̤Θ᷆ ༽!! ༼: ᷇Θ̵̵̵̤Θ᷆:#༽ ☕ ͜ ༼ ᷇Θ̵̵̵̤Θ᷆ ⍤༽";
        Invoke("ToolTip", Time.deltaTime);//这里本来是想着加载时间长的话可以隔一段时间换一个提示信息
        StartCoroutine(StartLoading());//加载
    }
    IEnumerator StartLoading()
    {
        float i = 0;
        float pro = 0;
        async = EnterDoor.LoadSceneAsync(loadName);
        async.allowSceneActivation = false;//控制加载场景是否激活
        while (i < 100)
        {
            pro = async.progress;
            if (i < async.progress * 100)
                i++;
            else if (async.progress >= 0.9f)
                i++;
            slider.value = i / 100;
            percent.text = i.ToString() + "%";
            yield return new WaitForEndOfFrame();
        }
        async.allowSceneActivation = true;
    }
    void ToolTip()
    {
        int i = Random.Range(0, tip.Length);
        toolTip.text = tip[i];
    }
}

最后附上我做好的二张图片


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值