【问题标题】:Execute NGUI button press from script in unity C#在统一 C# 中从脚本执行 NGUI 按钮按下
【发布时间】:2019-11-02 04:41:16
【问题描述】:

我有一个 NGUI 按钮,它包含 UIButtonUIToggle 脚本。从另一个脚本中,我想运行它的 click 事件以及所有相关的按钮状态变化,如颜色变化等。为此,我找到了 this link,这是我的代码。

   public UIButton userManagmentBtn;
    public void ClosePanel()
    {
        Debug.Log("Calling panel Colse");
        EventDelegate.Execute(userManagmentBtn.onClick);
    }

但是点击事件没有使用这个触发:EventDelegate.Execute

【问题讨论】:

    标签: c# unity3d events ngui


    【解决方案1】:

    没有 NGUI 专家,但 afaik 可以调用您可以简单调用的所有侦听器

    userManagementBtn.OnClick();
    

    另外,为了获得正确的颜色等,您可以致电SetState

    userManagementBtn.SetState(UIButtonColor.State.Pressed, true);
    

    或者,您可以尝试通过ExecuteEvents.Execute“手动”发送相应的指针事件,例如

    var pointer = new PointerEventData(EventSystem.current);
    ExecuteEvents.Execute(userManagementBtn.gameObject, pointer, ExecuteEvents.pointerEnterHandler);
    ExecuteEvents.Execute(userManagementBtn.gameObject, pointer, ExecuteEvents.pointerClickHandler);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多