zoukankan      html  css  js  c++  java
  • NGUI无法按住鼠标按住时无法监听OnHover事件

    UICamera.cs

    修改前:

     if ((!isPressed) && highlightChanged)
            {
                currentScheme = ControlScheme.Mouse;
                mTooltipTime = RealTime.time + tooltipDelay;
                mHover = mMouse[0].current;
                Notify(mHover, "OnHover", true);
            }

    修改后:

     if ((!isPressed || isPressed) && highlightChanged)
            {
                currentScheme = ControlScheme.Mouse;
                mTooltipTime = RealTime.time + tooltipDelay;
                mHover = mMouse[0].current;
                Notify(mHover, "OnHover", true);
            }

    或者加一个

    if (Input.GetMouseButton(0) && highlightChanged)
            {
                currentScheme = ControlScheme.Mouse;
                mTooltipTime = RealTime.time + tooltipDelay;
                mHover = mMouse[0].current;
                Notify(mHover, "OnHover", true);
            }
    if ((justPressed || !isPressed) && mHover != null && highlightChanged)
            {
                currentScheme = ControlScheme.Mouse;
                if (mTooltip != null) ShowTooltip(false);
                Notify(mHover, "OnHover", false);
                mHover = null;
            }
    
            if ((justPressed || Input.GetMouseButton(0)) && mHover != null && highlightChanged)
            {
                currentScheme = ControlScheme.Mouse;
                if (mTooltip != null) ShowTooltip(false);
                Notify(mHover, "OnHover", false);
                mHover = null;
            }

    监听函数

     void OnHover(bool state)
        {
            Debug.Log(state+"OnHover"+gameObject.name);
        }

     补充:

    因为UICamera.cs 的Update函数里处理是:

       void Update()
        {
            // Only the first UI layer should be processing events
    #if UNITY_EDITOR
            if (!Application.isPlaying || !handlesEvents) return;
    #else
            if (!handlesEvents) return;
    #endif
            current = this;
    
            // Process touch events first  如果是移动平台就调用的ProcessTouches()函数所以之前加的方法 在两个函数里都加上。
            if (useTouch) ProcessTouches();
            else if (useMouse) ProcessMouse();
  • 相关阅读:
    Codeforces Round #733
    [ZJOI2007] 时态同步(树形dp)
    最大子树和(树形dp)
    P2015 二叉苹果树
    没有上司的舞会(经典树形dp)
    P3884 [JLOI2009]二叉树问题(LCA)
    Bin Packing Problem(线段树 + multiset)
    P4281 [AHOI2008]紧急集合 / 聚会(最近公共祖先)
    P3128 [USACO15DEC]Max Flow P(LCA 树上差分)
    java中Set接口用法
  • 原文地址:https://www.cnblogs.com/123ing/p/3931679.html
Copyright © 2011-2022 走看看