【Unity3D】【NGUI】如何動態給EventDelegate添加參數,unity3dngui

來源:互聯網
上載者:User

【Unity3D】【NGUI】如何動態給EventDelegate添加參數,unity3dngui

NGUI討論群:333417608

NGUI版本:3.6.8


注意:參數必須是公用成員變數,不能是棧上的、或者私人的(就是臨時在函數裡面定義的或者是函數的參數都不行)

using UnityEngine;using System.Collections;public class SZEventDelegateParams : MonoBehaviour {public int param = 2;void Start(){// 建立新的delegate,最後調用此(this)指令碼的Finished函數。當然this可以換成別的指令碼,這裡為了方便EventDelegate eventDelegate = new EventDelegate(this, "Finished");// 把第一個參數設定為此(this)指令碼的param變數。當然this可以換成別的指令碼,這裡為了方便eventDelegate.parameters[0] = new EventDelegate.Parameter(this, "param");UIPlayTween uipt = this.GetComponent<UIPlayTween>();uipt.onFinished.Add(eventDelegate);uipt.Play(true);}// PlayTween 結束後,會調用到這裡,列印相應的值void Finished(int p){Debug.Log(p.ToString());}}



問Unity3d,怎用代碼控制NGUI控制項,如Button、Lable、SlicedSprite等

很簡單的啊

public UILabel text;
聲明,然後指令碼給一個物體,直接把label拖上去,然後引用的 時候直接使用text.text = "中文";
這是label。
至於button你想問的是按鈕的事件嗎?
添加指令碼buttonmessage,然後把寫有事件的指令碼拖給target,下面的function name填你的方法名
 
Unity3d怎獲得NGUI建立的Input組件的lable的常值內容並傳遞?

先定義一個public 變數

public UILable lable;

然後把INPUT的LABLE拽到lable上,這個應該會吧。

然後 lable.text 就是常值內容,

if(button){
彈出window;

window.text = lable.text;

}

就這樣就行了,上面的是虛擬碼。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.