/// <summary> /// Solve the flash problem! (JCS_CheckableObject) /// /// Check if the mouse still on top of the image! /// /// ATTENTIOIN(jenchieh): this will not work on the /// resizable window. /// </summary> /// <returns></returns> public static bool MouseOverGUI(RectTransform imageRect, RectTransform rootPanel = null) { Vector2 mousePos = JCS_Input.MousePositionOnGUILayer(); Vector2 checkPos = imageRect.localPosition; if (rootPanel != null) { checkPos += new Vector2(rootPanel.localPosition.x, rootPanel.localPosition.y); } // this item image size Vector2 slotRect = imageRect.sizeDelta; float halfSlotWidth = slotRect.x / 2 * imageRect.localScale.x; float halfSlotHeight = slotRect.y / 2 * imageRect.localScale.y; float leftBorder = checkPos.x - halfSlotWidth; float rightBorder = checkPos.x + halfSlotWidth; float topBorder = checkPos.y + halfSlotHeight; float bottomBorder = checkPos.y - halfSlotHeight; // Basic AABB collide math if (mousePos.x <= rightBorder && mousePos.x >= leftBorder && mousePos.y <= topBorder && mousePos.y >= bottomBorder) { return(true); } return(false); }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions public void FollowMouse(JCS_2D8Direction point) { if (mPanelRectTransform == null) { return; } // point we going to pop this dialogue Vector3 showPoint = JCS_Input.MousePositionOnGUILayer(); Vector2 dialogueRect = mPanelRectTransform.sizeDelta; float halfPanelWidth = dialogueRect.x / 2 * mPanelRectTransform.localScale.x; float halfPanelHeight = dialogueRect.y / 2 * mPanelRectTransform.localScale.x;; switch (point) { case JCS_2D8Direction.TOP: showPoint.y -= halfPanelHeight; break; case JCS_2D8Direction.BOTTOM: showPoint.y += halfPanelHeight; break; case JCS_2D8Direction.RIGHT: showPoint.x -= halfPanelWidth; break; case JCS_2D8Direction.LEFT: showPoint.x += halfPanelWidth; break; case JCS_2D8Direction.TOP_LEFT: showPoint.y -= halfPanelHeight; showPoint.x += halfPanelWidth; break; case JCS_2D8Direction.TOP_RIGHT: showPoint.y -= halfPanelHeight; showPoint.x -= halfPanelWidth; break; case JCS_2D8Direction.BOTTOM_LEFT: showPoint.y += halfPanelHeight; showPoint.x += halfPanelWidth; break; case JCS_2D8Direction.BOTTOM_RIGHT: showPoint.y += halfPanelHeight; showPoint.x -= halfPanelWidth; break; } this.mPanelRectTransform.localPosition = showPoint; if (mFitPushScreen) { FitPushScreen(); } }