// Polls the mouse pointing device protected void PollMouse(ref POINTER_INFO curPtr) { down = Input.GetMouseButton(0); // If the device is pressed and it // was already pressed, it's a drag // or a repeat, depending on if there // was movement: if (down && curPtr.active) { // Drag: if (Input.mousePosition != curPtr.devicePos) { curPtr.evt = POINTER_INFO.INPUT_EVENT.DRAG; curPtr.inputDelta = Input.mousePosition - curPtr.devicePos; curPtr.devicePos = Input.mousePosition; // See if we have exceeded the drag threshold: if (curPtr.isTap) { tempVec = curPtr.origPos - curPtr.devicePos; if (Mathf.Abs(tempVec.x) > dragThreshold || Mathf.Abs(tempVec.y) > dragThreshold) curPtr.isTap = false; } } else { // Nothing to see here: curPtr.evt = POINTER_INFO.INPUT_EVENT.NO_CHANGE; curPtr.inputDelta = Vector3.zero; } } else if (down && !curPtr.active) // Else if it's a new press, it's a press { curPtr.Reset(curActionID++); curPtr.evt = POINTER_INFO.INPUT_EVENT.PRESS; curPtr.active = true; curPtr.inputDelta = Input.mousePosition - curPtr.devicePos; curPtr.origPos = Input.mousePosition; curPtr.isTap = true; // True for now, until it moves too much } else if (!down && curPtr.active) // A release { curPtr.inputDelta = Input.mousePosition - curPtr.devicePos; curPtr.devicePos = Input.mousePosition; // See if we have exceeded the drag threshold: if (curPtr.isTap) { tempVec = curPtr.origPos - curPtr.devicePos; if (Mathf.Abs(tempVec.x) > dragThreshold || Mathf.Abs(tempVec.y) > dragThreshold) curPtr.isTap = false; } if (curPtr.isTap) curPtr.evt = POINTER_INFO.INPUT_EVENT.TAP; else curPtr.evt = POINTER_INFO.INPUT_EVENT.RELEASE; curPtr.active = false; } else if (!down && Input.mousePosition != curPtr.devicePos) // Mouse was moved { curPtr.evt = POINTER_INFO.INPUT_EVENT.MOVE; curPtr.inputDelta = Input.mousePosition - curPtr.devicePos; curPtr.devicePos = Input.mousePosition; } else { curPtr.evt = POINTER_INFO.INPUT_EVENT.NO_CHANGE; curPtr.inputDelta = Vector3.zero; } curPtr.devicePos = Input.mousePosition; curPtr.prevRay = curPtr.ray; curPtr.ray = uiCameras[0].camera.ScreenPointToRay(curPtr.devicePos); }
// Polls the mouse pointing device protected void PollMouse(ref POINTER_INFO curPtr) { down = Input.GetMouseButton(0); // Check for scroll wheel: float scrollDelta = Input.GetAxis("Mouse ScrollWheel"); #if SCROLL_IS_TIME_COHERENT scrollDelta *= Time.deltaTime; #endif bool scrolled = (scrollDelta != 0); // If the device is pressed and it // was already pressed, it's a drag // or a repeat, depending on if there // was movement: if (down && curPtr.active) { // Drag: if (Input.mousePosition != curPtr.devicePos) { curPtr.evt = POINTER_INFO.INPUT_EVENT.DRAG; curPtr.inputDelta = Input.mousePosition - curPtr.devicePos; curPtr.devicePos = Input.mousePosition; // See if we have exceeded the drag threshold: if (curPtr.isTap) { tempVec = curPtr.origPos - curPtr.devicePos; if (Mathf.Abs(tempVec.x) > dragThreshold || Mathf.Abs(tempVec.y) > dragThreshold) curPtr.isTap = false; } } else { // Nothing to see here: curPtr.evt = POINTER_INFO.INPUT_EVENT.NO_CHANGE; curPtr.inputDelta = Vector3.zero; } } else if (down && !curPtr.active) // Else if it's a new press, it's a press { curPtr.Reset(curActionID++); curPtr.evt = POINTER_INFO.INPUT_EVENT.PRESS; curPtr.active = true; curPtr.inputDelta = Input.mousePosition - curPtr.devicePos; curPtr.origPos = Input.mousePosition; curPtr.isTap = true; // True for now, until it moves too much curPtr.activeTime = Time.time; } else if (!down && curPtr.active) // A release { curPtr.inputDelta = Input.mousePosition - curPtr.devicePos; curPtr.devicePos = Input.mousePosition; // See if we have exceeded the drag threshold: if (curPtr.isTap) { tempVec = curPtr.origPos - curPtr.devicePos; if (Mathf.Abs(tempVec.x) > dragThreshold || Mathf.Abs(tempVec.y) > dragThreshold) curPtr.isTap = false; } if (curPtr.isTap) curPtr.evt = POINTER_INFO.INPUT_EVENT.TAP; else curPtr.evt = POINTER_INFO.INPUT_EVENT.RELEASE; curPtr.active = false; curPtr.activeTime = 0; } else if (!down && Input.mousePosition != curPtr.devicePos) // Mouse was moved { curPtr.evt = POINTER_INFO.INPUT_EVENT.MOVE; curPtr.inputDelta = Input.mousePosition - curPtr.devicePos; curPtr.devicePos = Input.mousePosition; } else { curPtr.evt = POINTER_INFO.INPUT_EVENT.NO_CHANGE; curPtr.inputDelta = Vector3.zero; } // Add any scroll delta in to the Z coordinate: if (scrolled) { curPtr.inputDelta.z = scrollDelta; } curPtr.devicePos = Input.mousePosition; curPtr.prevRay = curPtr.ray; curPtr.ray = uiCameras[0].camera.ScreenPointToRay(curPtr.devicePos); }