IEnumerator ProcessDataPerFrame() { while (true) { yield return(new WaitForEndOfFrame()); if (receivedData.Count > 0) { DeviceData newData; List <WirelessTouch> allTouches = new List <WirelessTouch>(); //loop through all received data for (int i = 0; i < receivedData.Count; i++) { var dat = receivedData[i]; for (int t = 0; t < dat.TouchData.Length; t++) { WirelessTouch currentTouch = dat.TouchData[t]; int foundTouchIndex = allTouches.FindIndex(T => T.fingerId == currentTouch.fingerId); if (foundTouchIndex >= 0) { if (currentTouch.phase == TouchPhase.Began || currentTouch.phase == TouchPhase.Ended) { allTouches[foundTouchIndex].phase = currentTouch.phase; } } else { allTouches.Add(currentTouch); } } } newData = receivedData[receivedData.Count - 1]; newData.TouchData = allTouches.ToArray(); data = newData; receivedData.Clear(); } } }
private void ProcessTouchEvents() { for (int i = 0; i < data.TouchData.Length; ++i) { WirelessTouch input = data.TouchData[i]; bool released = input.phase == TouchPhase.Ended; bool pressed = true; var pointer = this.GetTouchPointerEventData(input, out pressed, out released); ProcessTouchPress(pointer, pressed, released); if (!released) { ProcessMove(pointer); ProcessDrag(pointer); } else { RemovePointerData(pointer); } } }
PointerEventData GetTouchPointerEventData(WirelessTouch input, out bool pressed, out bool released) { PointerEventData pointerData; var created = GetPointerData(input.fingerId, out pointerData, true); pointerData.Reset(); pressed = created || (input.phase == TouchPhase.Began); released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended); if (created) { pointerData.position = input.position; } if (pressed) { pointerData.delta = Vector2.zero; } else { pointerData.delta = input.position - pointerData.position; } pointerData.position = input.position; pointerData.button = PointerEventData.InputButton.Left; eventSystem.RaycastAll(pointerData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); pointerData.pointerCurrentRaycast = raycast; m_RaycastResultCache.Clear(); return(pointerData); }