public void Clear() { touchable = null; doesHaveTouch = false; didJustBegin = false; didJustEnd = false; didJustMove = false; didJustCancel = false; wasArtificiallyCanceled = false; }
public void Clear() { touchable = null; doesHaveTouch = false; didJustBegin = false; didJustEnd = false; didJustMove = false; didJustCancel = false; wasArtificiallyCanceled = false; }
private static int CapturablePriorityComparison(FCapturedTouchableInterface a, FCapturedTouchableInterface b) { return(b.touchPriority - a.touchPriority); //highest to lowest }
public void Update() { if (!isEnabled) { return; } if (_needsPrioritySort) { UpdatePrioritySorting(); } //create non-changeable temporary copies of the lists //this is so that there won't be problems if touchables are removed/added while being iterated through FMultiTouchableInterface[] tempMultiTouchables = _multiTouchables.ToArray(); FCapturedTouchableInterface[] tempCapturedTouchables = _capturedTouchables.ToArray(); float touchScale = 1.0f / Futile.displayScale; //the offsets account for the camera's 0,0 point (eg, center, bottom left, etc.) float offsetX = -Futile.screen.originX * Futile.screen.pixelWidth; float offsetY = -Futile.screen.originY * Futile.screen.pixelHeight; //Debug.Log ("Touch offset " + offsetX + " , " + offsetY); bool wasMouseTouch = false; FTouch mouseTouch = new FTouch(); if (shouldMouseEmulateTouch) { mouseTouch.position = new Vector2((Input.mousePosition.x + offsetX) * touchScale, (Input.mousePosition.y + offsetY) * touchScale); mouseTouch.fingerId = 0; mouseTouch.tapCount = 1; mouseTouch.deltaTime = Time.deltaTime; if (Input.GetMouseButtonDown(0)) { mouseTouch.deltaPosition = new Vector2(0, 0); _previousMousePosition = mouseTouch.position; mouseTouch.phase = TouchPhase.Began; wasMouseTouch = true; } else if (Input.GetMouseButtonUp(0)) { mouseTouch.deltaPosition = new Vector2(mouseTouch.position.x - _previousMousePosition.x, mouseTouch.position.y - _previousMousePosition.y); _previousMousePosition = mouseTouch.position; mouseTouch.phase = TouchPhase.Ended; wasMouseTouch = true; } else if (Input.GetMouseButton(0)) { mouseTouch.deltaPosition = new Vector2(mouseTouch.position.x - _previousMousePosition.x, mouseTouch.position.y - _previousMousePosition.y); _previousMousePosition = mouseTouch.position; mouseTouch.phase = TouchPhase.Moved; wasMouseTouch = true; } } int touchCount = Input.touchCount; int offset = 0; if (wasMouseTouch) { touchCount++; } FTouch[] touches = new FTouch[touchCount]; if (wasMouseTouch) { touches[0] = mouseTouch; offset = 1; } for (int i = 0; i < Input.touchCount; ++i) { Touch sourceTouch = Input.GetTouch(i); FTouch resultTouch = new FTouch(); resultTouch.deltaPosition = new Vector2(sourceTouch.deltaPosition.x * touchScale, sourceTouch.deltaPosition.y * touchScale); resultTouch.deltaTime = sourceTouch.deltaTime; resultTouch.fingerId = sourceTouch.fingerId + offset; resultTouch.phase = sourceTouch.phase; resultTouch.position = new Vector2((sourceTouch.position.x + offsetX) * touchScale, (sourceTouch.position.y + offsetY) * touchScale); resultTouch.tapCount = sourceTouch.tapCount; touches[i + offset] = resultTouch; } int capturedTouchableCount = tempCapturedTouchables.Length; //reset the touch slotIndexes so that each slot can pick the touch it needs for (int t = 0; t < touchCount; t++) { FTouch touch = touches[t]; touch.slot = null; } //match up slots that are currently active with the touches for (int s = 0; s < SLOT_COUNT; s++) { FTouchSlot slot = _touchSlots[s]; if (slot.doesHaveTouch) { bool didFindMatchingTouch = false; for (int t = 0; t < touchCount; t++) { FTouch touch = touches[t]; if (slot.touch.fingerId == touch.fingerId) { didFindMatchingTouch = true; slot.touch = touch; touch.slot = slot; break; } } if (!didFindMatchingTouch) { slot.doesHaveTouch = false; slot.touchable = null; } } } //fill any blank slots with the unclaimed touches for (int s = 0; s < SLOT_COUNT; s++) { FTouchSlot slot = _touchSlots[s]; if (!slot.doesHaveTouch) { for (int t = 0; t < touchCount; t++) { FTouch touch = touches[t]; if (touch.slot == null) { slot.touch = touch; slot.doesHaveTouch = true; touch.slot = slot; break; } } } if (slot.doesHaveTouch) //send the touch out to the slots that need it { if (slot.touch.phase == TouchPhase.Began) { for (int c = 0; c < capturedTouchableCount; c++) { FCapturedTouchableInterface capturedTouchable = tempCapturedTouchables[c]; FSingleTouchableInterface singleTouchable = capturedTouchable as FSingleTouchableInterface; //the first touchable to return true becomes the active one if (slot.index == 0 && singleTouchable != null && singleTouchable.HandleSingleTouchBegan(slot.touch)) { slot.isSingleTouchable = true; slot.touchable = capturedTouchable; break; } else { FSmartTouchableInterface smartTouchable = capturedTouchable as FSmartTouchableInterface; if (smartTouchable != null && smartTouchable.HandleSmartTouchBegan(slot.index, slot.touch)) { slot.isSingleTouchable = false; slot.touchable = capturedTouchable; break; } } } } else if (slot.touch.phase == TouchPhase.Moved) { if (slot.touchable != null) { if (slot.isSingleTouchable) { (slot.touchable as FSingleTouchableInterface).HandleSingleTouchMoved(slot.touch); } else { (slot.touchable as FSmartTouchableInterface).HandleSmartTouchMoved(slot.index, slot.touch); } } } else if (slot.touch.phase == TouchPhase.Ended) { if (slot.touchable != null) { if (slot.isSingleTouchable) { (slot.touchable as FSingleTouchableInterface).HandleSingleTouchEnded(slot.touch); } else { (slot.touchable as FSmartTouchableInterface).HandleSmartTouchEnded(slot.index, slot.touch); } } slot.touchable = null; slot.doesHaveTouch = false; } else if (slot.touch.phase == TouchPhase.Canceled) { if (slot.touchable != null) { if (slot.isSingleTouchable) { (slot.touchable as FSingleTouchableInterface).HandleSingleTouchCanceled(slot.touch); } else { (slot.touchable as FSmartTouchableInterface).HandleSmartTouchCanceled(slot.index, slot.touch); } } slot.touchable = null; slot.doesHaveTouch = false; } } else //clear the slot here { slot.touchable = null; slot.doesHaveTouch = false; } } if (touchCount > 0) { int multiTouchableCount = tempMultiTouchables.Length; for (int m = 0; m < multiTouchableCount; m++) { tempMultiTouchables[m].HandleMultiTouch(touches); } } }
private static int CapturablePriorityComparison(FCapturedTouchableInterface a, FCapturedTouchableInterface b) { return b.touchPriority - a.touchPriority; //highest to lowest }