public static List <txUIObject> raycast(Ray ray, SortedDictionary <UIDepth, List <txUIObject> > buttonList, int maxCount = 0) { bool cast = true; List <txUIObject> retList = new List <txUIObject>(); RaycastHit hit = new RaycastHit(); foreach (var box in buttonList) { int count = box.Value.Count; for (int i = 0; i < count; ++i) { txUIObject window = box.Value[i]; BoxCollider collider = window.getBoxCollider(); if (window.getHandleInput() && collider.Raycast(ray, out hit, 10000.0f)) { retList.Add(window); // 如果射线不能穿透当前按钮,或者已经达到最大数量,则不再继续 if (!window.getPassRay() || maxCount > 0 && retList.Count >= maxCount) { cast = false; break; } } } if (!cast) { break; } } return(retList); }
public void update(float elapsedTime) { if (!mUseHover) { return; } // 鼠标移动检测 Vector3 curMousePosition = getCurMousePosition(); if (mLastMousePosition != curMousePosition) { // 计算鼠标当前所在最前端的窗口 txUIObject newWindow = getHoverButton(curMousePosition); // 判断鼠标是否还在当前窗口内 if (mHoverButton != null) { // 鼠标已经移动到了其他窗口中,发送鼠标离开的事件 if (newWindow != mHoverButton) { // 不过也许此时悬停窗口已经不接收输入事件了或者碰撞盒子被禁用了,需要判断一下 if (mHoverButton.getHandleInput() && mHoverButton.getBoxCollider().enabled) { hoverWindow(mHoverButton, false); } // 找到鼠标所在的新的窗口,给该窗口发送鼠标进入的事件 hoverWindow(newWindow, true); } } // 如果上一帧鼠标没有在任何窗口内,则计算这一帧鼠标所在的窗口 else { // 发送鼠标进入的事件 hoverWindow(newWindow, true); } mHoverButton = newWindow; mLastMousePosition = curMousePosition; } }
public override void update(float elapsedTime) { if (!mUseHover || !mUseGlobalTouch) { return; } // 模拟触摸时,更新触摸点 if (mSimulateTouch && mMousePressed) { mCurTouchPosition = Input.mousePosition; } // 鼠标移动检测 Vector3 curMousePosition = getCurMousePosition(); if (mLastMousePosition != curMousePosition) { // 计算鼠标当前所在最前端的窗口 txUIObject newWindow = getHoverButton(curMousePosition); // 判断鼠标是否还在当前窗口内 if (mHoverButton != null) { // 鼠标已经移动到了其他窗口中,发送鼠标离开的事件 if (newWindow != mHoverButton) { // 不过也许此时悬停窗口已经不接收输入事件了或者碰撞盒子被禁用了,需要判断一下 if (mHoverButton.getHandleInput() && mHoverButton.getBoxCollider().enabled) { hoverWindow(mHoverButton, false); } // 找到鼠标所在的新的窗口,给该窗口发送鼠标进入的事件 hoverWindow(newWindow, true); } } // 如果上一帧鼠标没有在任何窗口内,则计算这一帧鼠标所在的窗口 else { // 发送鼠标进入的事件 hoverWindow(newWindow, true); } mHoverButton = newWindow; if (mHoverButton != null) { Vector2 moveDelta = curMousePosition - mLastMousePosition; mHoverButton.onMouseMove(curMousePosition, moveDelta, getLength(moveDelta) / elapsedTime); } mLastMousePosition = curMousePosition; mCurStayTime = 0.0f; } else { if (mCurStayTime >= 0.0f) { mCurStayTime += elapsedTime; if (mCurStayTime >= mStayTime) { mCurStayTime = -1.0f; if (mHoverButton != null) { mHoverButton.onMouseStay(curMousePosition); } } } } }