public void ProcessMouse(MouseData data) { ivec2 mouseLocation = data.Location; if (hoveredItem != null && !hoveredItem.Contains(mouseLocation)) { hoveredItem.OnUnhover(); hoveredItem = null; } foreach (IClickable item in Items) { if (item != hoveredItem && item.Contains(mouseLocation)) { // It's possible for the mouse to move between items in a single frame. hoveredItem?.OnUnhover(); hoveredItem = item; hoveredItem.OnHover(mouseLocation); break; } } // It's also possible for the mouse to move to a new item and click on the same frame (which is rare, but // considered a valid click). if (hoveredItem != null && data.Query(GLFW_MOUSE_BUTTON_LEFT, InputStates.PressedThisFrame)) { hoveredItem.OnClick(mouseLocation); } }
public override void Execute(float d) { PointerEventData pointerData = new PointerEventData(EventSystem.current); pointerData.position = Input.mousePosition; List <RaycastResult> results = new List <RaycastResult>(); //get all objects our pointer is overlapping with EventSystem.current.RaycastAll(pointerData, results); foreach (RaycastResult r in results) { IClickable c = r.gameObject.GetComponentInParent <IClickable>(); if (c != null) { c.OnHover(); break; } } }