NGUI与UGUI制作Loading条

加载过程需要自己编写脚本,命名为ProgressBar_Test往里面添加代码:

变量部分:

    public UIProgressBar bar;
    public UILabel label;
    public UIEasing.EasingType easing = UIEasing.EasingType.easeLinear;
    public float duration = 2f;
    public float startDelay = 0f;
    public float holdTime = 1f;
    public bool startFromZero = false;
    private bool started = false;
    private bool ascending = false;

一运行时执行:

void Start()
    {
        if (this.bar == null)
            this.bar = this.GetComponent<UIProgressBar>();

        if (this.startFromZero)
        {
            this.ascending = true;
            this.bar.value = 0f;
            this.UpdateLabel();
        }
    }

当Bar存在的时候放在OnEnable中执行:

更新部分代码:

这个脚本挂上后即完成了下载条的加载动画部分,下面需要加载完跳转进入下一个场景:

脚本命名:LoadSceneTest代码部分如下

    public string sceneName;//这个直接在Inspector面板中填上需要跳转的场景的名字就行
    public UIProgressBar bar;
    public float requiredValue = 1f;
    public bool ignoreFirst = true;

    public void LoadScene()
    {
        Application.LoadLevel(sceneName);
    }

    //给脚本UIProgressbar脚本的OnValueChange赋值
    public void OnProgress()
    {
        if (this.ignoreFirst)
        {
            this.ignoreFirst = false;
            return;
        }

        if (this.bar != null && this.bar.value >= this.requiredValue)
            LoadScene();
    }

NGUI的比较简单因为出来得早很成熟了,我主要是做个笔记,接下来写下用UGUI实现的方法

相比而言,简单多了,所以还是新生的好吧,只需要一个背景Image再加上一个filled类型的Image

再添加一个Text文本就可以制作了,代码也可以很简洁,贴上:

 public UnityEngine.UI.Text text;
 public UnityEngine.UI.Image loadbar;   
    IEnumerator Start()
    {
        for (int i = 0; i < 120; i++)
        {
            loadbar.fillAmount += 1 / 120f;
            text.text = ((i+1) * 100 / 120).ToString() + "%";

小细节就是从0开始到99就跳转了,从1开始正好百分之百

            yield return new WaitForEndOfFrame();
        }
       
        SceneManager.LoadScene("HomeScene");

这里的名字也可以像上面那样从面板里填,这样写也行,简单点如果不改场景名的话

    }

随着版本的更新,再进行修改,目前还是觉得UGUI顺手,毕竟我一开始学就是用的ugui,NGUI还有适应中,最近

又出了个FairyGUI,国内的一插件挺好用,有空看看。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

瓜皮肖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值