예제 #1
0
    public static List <txUIButton> raycast(Ray ray, SortedDictionary <int, List <txUIButton> > buttonList, int maxCount = 0)
    {
        bool cast = true;
        List <txUIButton> retList = new List <txUIButton>();
        RaycastHit        hit     = new RaycastHit();

        foreach (var box in buttonList)
        {
            int count = box.Value.Count;
            for (int i = 0; i < count; ++i)
            {
                txUIButton button = box.Value[i];
                if (button.getHandleInput() && button.Raycast(ray, out hit, 10000.0f))
                {
                    retList.Add(button);
                    // 如果射线不能穿透当前按钮,或者已经达到最大数量,则不再继续
                    if (!button.getPassRay() || maxCount > 0 && retList.Count >= maxCount)
                    {
                        cast = false;
                        break;
                    }
                }
            }
            if (!cast)
            {
                break;
            }
        }
        return(retList);
    }
예제 #2
0
    public void update(float elapsedTime)
    {
        if (!mUseHover)
        {
            return;
        }
        // 鼠标移动检测
        Vector3 curMousePosition = getCurMousePosition();

        if (mLastMousePosition != curMousePosition)
        {
            // 计算鼠标当前所在最前端的窗口
            txUIButton newWindow = getHoverButton(curMousePosition);
            // 判断鼠标是否还在当前窗口内
            if (mHoverButton != null)
            {
                // 鼠标已经移动到了其他窗口中,发送鼠标离开的事件
                if (newWindow != mHoverButton)
                {
                    // 不过也许此时悬停窗口已经不接收输入事件了或者碰撞盒子被禁用了,需要判断一下
                    if (mHoverButton.getHandleInput() && mHoverButton.getBoxCollider().enabled)
                    {
                        if (mButtonCallbackList[mHoverButton].mHoverCallback != null)
                        {
                            mButtonCallbackList[mHoverButton].mHoverCallback(mHoverButton, false);
                        }
                    }
                    // 找到鼠标所在的新的窗口,给该窗口发送鼠标进入的事件
                    if (newWindow != null)
                    {
                        if (mButtonCallbackList[newWindow].mHoverCallback != null)
                        {
                            mButtonCallbackList[newWindow].mHoverCallback(newWindow, true);
                        }
                    }
                }
            }
            // 如果上一帧鼠标没有在任何窗口内,则计算这一帧鼠标所在的窗口
            else
            {
                // 发送鼠标进入的事件
                if (newWindow != null)
                {
                    if (mButtonCallbackList[newWindow].mHoverCallback != null)
                    {
                        mButtonCallbackList[newWindow].mHoverCallback(newWindow, true);
                    }
                }
            }
            mHoverButton       = newWindow;
            mLastMousePosition = curMousePosition;
        }
    }
예제 #3
0
    public txUIButton getHoverButton(Vector3 pos)
    {
        // 返回Layout深度最大的,也就是最靠前的窗口
        List <BoxCollider> boxList       = globalRaycast(pos);
        txUIButton         forwardButton = null;

        foreach (var box in boxList)
        {
            txUIButton button = mBoxColliderCallbackList[box].mButton;
            GameLayout layout = button.mLayout;
            if (forwardButton == null || (button.getHandleInput() && layout.getRenderOrder() > forwardButton.mLayout.getRenderOrder()))
            {
                forwardButton = button;
            }
        }
        return(forwardButton);
    }