unity3D遊戲開發十六之NGUI三

來源:互聯網
上載者:User

接下來我們看下ProgeressBar,進度條,它是UISlider和UIScrollBar的基類,屬性如:


Value:百分比

Alpha:透明度

Steps:步閥閾值

Appearance:特性

a.Foreground(前景圖片)

b.Background(背景圖片)

d.Direction(滑動方向)

On Value Change:當滑動時,進行事件分發

下面我們做一個進度條,每過一秒進度加1,準備兩個sprite作為前景圖片跟背景圖片,如:


我們修改Test指令碼,代碼如:

using UnityEngine;using System.Collections;public class Test : MonoBehaviour {//public UIInput username; public UIProgressBar progressBr;private UILabel plabel;void Awake (){//Debug.Log("----111");////擷取需要監聽的按鈕對象//GameObject button=GameObject.Find("UI Root (2D)/Camera/Anchor/Panel/Button");////設定這個按鈕的監聽,指向本類的ButtonClick方法中//UIEventListener.Get(button).onClick=buttonClick;progressBr=GetComponent<UIProgressBar>();progressBr.value=0;GameObject ob=GameObject.FindWithTag("111");plabel=ob.GetComponent<UILabel>();}// Use this for initializationvoid Start () {}// Update is called once per framevoid Update (){if(progressBr!=null){progressBr.value+=0.01f*Time.deltaTime;string shuzhi=(progressBr.value * 100).ToString("#0.00");plabel.text=shuzhi+"%";}}//void buttonClick(GameObject button)//{//////Debug.Log("username:"+username.value);//////Debug.Log("GameObject:"+button.name);//////}}
綁定指令碼,設定對象,如:


預覽遊戲,如:


下面我們看下UISlider,UISlider組件可以用來建立一個簡單的slider和進度條。繼承了UIProgressBar的所有功能,之後增加了可選的滑塊,屬性如:


效果如下:


接下來我們看下UIScrollBar,UIScrollBar用來建立捲軸——可變長度的滑動條在大小固定的地區移動。它繼承了所有UIprogressBar的功能,僅僅修改了前景的顯示方式,變為可以被移動位置並且可以互動,屬性如:


與UISlider類似,UIScrollBar需要引用一個Foreground widget。當Size值為1(100%)的時候,這個widget就會佔用捲軸的最大尺寸,效果如:



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.