public override void UpdateTouches(FSInputManager oic) { for (int i = 0; i < Input.touchCount; i++) { UnityEngine.Touch touch = Input.GetTouch(i); FSInputTouch fingerTouch = oic.findOrCreateTouch(touch.fingerId); fingerTouch.IsActive = true; fingerTouch.UpdatePosition(touch.position.x, Screen.height - touch.position.y); } }
public override void UpdateTouches(FSInputManager oic) { if (tuioTracking != null) { tuioTracking.BuildTouchDictionary(); foreach (KeyValuePair <int, Tuio.Touch> touch in tuioTracking.AllTouches) { FSInputTouch fingerTouch = oic.findOrCreateTouch(touch.Key); fingerTouch.IsActive = true; fingerTouch.UpdatePosition(touch.Value.RawPoint.x * Screen.width, touch.Value.RawPoint.y * Screen.height); } } }
private void UpdateControlState() { if (!isUpdated) { Vector2 defaultTouchPosition = new Vector2(0, 0); bool defaultTouchActive = false; //Reset touches if (aliveTouches != null) { foreach (FSInputTouch testTouch in aliveTouches) { testTouch.ResetLastState(); } } if (defaultTouch != null) { defaultTouchPosition = defaultTouch.Position; defaultTouch.ResetLastState(); } if (aliveTouchesIds != null) { aliveTouchesIds.Clear(); } List <FSInputController> touchInputs = Manager.GetAllInstances <FSInputController>(); foreach (FSInputController ti in touchInputs) { ti.UpdateTouches(this); } /* * if(multitouchEnabled){ * * * }*/ if (aliveTouchesIds.Count == 0) { FSInputTouch fingerTouch = findOrCreateTouch(mouseToucheId); if (Input.mousePosition != savedMousePos) { fingerTouch.UpdatePosition(Input.mousePosition.x, Screen.height - Input.mousePosition.y); savedMousePos = Input.mousePosition; } fingerTouch.IsActive = Input.GetMouseButton(0); } //Joypad if (useJoypadAsMouse && joypadIsConnected) { FSInputTouch fingerTouch = findOrCreateTouch(mouseToucheId); if (GetAxisRaw("Click") == 1) { fingerTouch.IsActive = true; } fingerTouch.UpdatePosition(fingerTouch.Position.x + GetAxisRaw("Cursor X") * joypadCursorSpeed * Screen.width * Time.deltaTime, fingerTouch.Position.y - GetAxisRaw("Cursor Y") * joypadCursorSpeed * Screen.width * Time.deltaTime); } //Remove not active touches for (int i = aliveTouches.Count - 1; i >= 0; i--) { if (!aliveTouchesIds.Contains(aliveTouches[i].Id)) { aliveTouches[i].IsActive = false; aliveTouches.RemoveAt(i); } } int numTouches = aliveTouches.Count; if (numTouches == 1) { defaultTouchActive = aliveTouches[0].IsActive; defaultTouchPosition = aliveTouches[0].Position; } defaultTouch.IsActive = defaultTouchActive; defaultTouch.UpdatePosition(defaultTouchPosition.x, defaultTouchPosition.y); if (numTouches == 2) { FSInputTouch touch1 = aliveTouches[0]; FSInputTouch touch2 = aliveTouches[1]; float curDist = Vector2.Distance(touch1.Position, touch2.Position); if (touch1.IsMoving && touch2.IsMoving && savedZoomDist > 0) { deltaZoom = curDist / savedZoomDist; isZooming = true; } //Debug.Log("distance " + deltaZoom); savedZoomDist = curDist; } else { float scroll = GetAxisRaw("Zoom"); if (scroll != 0) { isZooming = true; desktopZoomSpeed += scroll / 10.0f; } else if (desktopZoomSpeed == 0) { isZooming = false; } deltaZoom = desktopZoom / desktopLastZoom; desktopZoom = 1.0f; } desktopLastZoom = desktopZoom; if (desktopZoomSpeed < -0.01f || desktopZoomSpeed > 0.01f) { desktopZoomSpeed -= desktopZoomSpeed * Time.deltaTime * 3; desktopZoom += desktopZoomSpeed * Time.deltaTime * 3; } else { desktopZoomSpeed = 0; } //Click processing hasBeenClicked = false; hasBeenSimpleClicked = false; if (defaultTouch.HasGoneActive) { lastGoneActiveTime = Time.time; } if (defaultTouch.HasGoneInactive) { if (((numClick == 0 && (Time.time - lastGoneActiveTime < clickTime)) || (Time.time - lastGoneInactiveTime < clickTime)) && defaultTouch.Distance < clickDistanceTolerance * dpiFactor) { hasBeenClicked = true; numClick++; if (Clicked != null) { Clicked(defaultTouch); } } lastGoneInactiveTime = Time.time; } else if (numClick > 0 && (Time.time - lastGoneInactiveTime > clickTime)) { numClick = 0; hasBeenSimpleClickedDone = false; } if (!hasBeenSimpleClickedDone && numClick == 1 && (Time.time - lastGoneActiveTime > clickTime)) { hasBeenSimpleClicked = true; hasBeenSimpleClickedDone = true; if (SimpleClicked != null) { SimpleClicked(defaultTouch); } } isUpdated = true; } }