7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Unity][NGUI] UIButtonのonClickイベントに引数を設定する

Last updated at Posted at 2014-12-06

環境

  • Unity 4.5.5
  • NGUI 3.7.4

イベントを設定するコード

// hogeMonoBehaviour の OnTapIcon メソッドに通知したい場合
EventDelegate onClickEvent = new EventDelegate(hogeMonoBehaviour, "OnTapIcon");

// OnTapIcon メソッドに渡すパラメータ
EventDelegate.Parameter param = onClickEvent.parameters[0];
param.obj = this;

// button は UIButton です
button.onClick.Add(onClickEvent);

イベントを受け取るコード

HogeMonoBehaviour.cs
public void OnTapIcon(Object obj)
{
    // do something...
}

Object と書いていますが、もちろん任意の型を渡せます。

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?