[英]Execute NGUI button press from script in unity C#
I have a NGUI button and it contains UIButton
and UIToggle
script.我有一个 NGUI 按钮,它包含
UIButton
和UIToggle
脚本。 From another script i want to run its click
event with all relevant button state changes like colour change etc. For this I found this link and here is my code.从另一个脚本中,我想使用所有相关按钮 state 更改(例如颜色更改等)来运行其
click
事件。为此,我找到了此链接,这是我的代码。
public UIButton userManagmentBtn;
public void ClosePanel()
{
Debug.Log("Calling panel Colse");
EventDelegate.Execute(userManagmentBtn.onClick);
}
But the click event is not firing using this: EventDelegate.Execute
但是点击事件没有使用这个触发:
EventDelegate.Execute
No NGUI expert but afaik to invoke all listeners you can simply call没有 NGUI 专家,但 afaik 可以调用您可以简单调用的所有侦听器
userManagementBtn.OnClick();
Additionally for having the correct coloring etc you could call SetState
此外,为了获得正确的颜色等,您可以调用
SetState
userManagementBtn.SetState(UIButtonColor.State.Pressed, true);
Alternatively you could try and send "manually" the according pointer events via ExecuteEvents.Execute
like eg或者,您可以尝试通过
ExecuteEvents.Execute
“手动”发送相应的指针事件,例如
var pointer = new PointerEventData(EventSystem.current);
ExecuteEvents.Execute(userManagementBtn.gameObject, pointer, ExecuteEvents.pointerEnterHandler);
ExecuteEvents.Execute(userManagementBtn.gameObject, pointer, ExecuteEvents.pointerClickHandler);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.