EZGUI的Input Delegate粗略翻译

大多数input控制都会通过一个代理的方法监听事件,在EZGUI中的input代理会用AddInputDelegate()方法去处理。

举例

首先,在脚本中定义一个代理的方法(必须用C#写,JS实现不了)

void MyDelegate(ref POINTER_INFO ptr)
{
   // Display a message in the console if
   // the pointer is dragged over the control:
   if(ptr.evt == POINTER_INFO.INPUT_EVENT.DRAG)
      Debug.Log("Dragged!");
}

下面就使用这个方法

void Start()
{
   // Get a reference to our control script:
   IUIObject control = (IUIObject) GetComponent(typeof(IUIObject));
   
   // Tell the control to call our method when it receives input:
   control.AddInputDelegate(MyDelegate);
}

假如我们有一个按钮,不想让它通过MOVE事件进入OVER态,我们就可以通过脚本来完成这个事。

void MyDelegate(ref POINTER_INFO ptr)
{
   if(ptr.evt == POINTER_INFO.INPUT_EVENT.MOVE)
      ptr.evt = POINTER_INFO.INPUT_EVENT.NO_CHANGE;
}
posted @ 2012-08-20 16:50  Marble  阅读(454)  评论(0编辑  收藏  举报