/* * Refresh touch data. */ public void Update() { if (GetComponent <StatusUI>()) //this is only required for StatusUI. { GetComponent <StatusUI>().currentInput = -1; } if (Input.touchCount > 0) //if touches are available { touches.Clear(); for (int i = 0; i < Input.touchCount; i++) { var t = Input.touches [i]; HandleInput(t.fingerId, t.phase, t.position, t.deltaPosition, t.GetForce(), t.GetMaxForce(), t.GetRadius(), t.GetRadiusTolerance()); } if (GetComponent <StatusUI>()) //this is only required for StatusUI. { GetComponent <StatusUI>().currentInput = 1; } } else //if unity touch is unavailable fallback to mouse input { touches.Clear(); var temp = new NativeTouchExtraData(); var mousePos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); if (Input.GetMouseButtonDown(0)) { HandleInput(mouseId, TouchPhase.Began, mousePos, Vector2.zero, temp.force, temp.maxforce, temp.radius, temp.radiusTolerance); } else if (Input.GetMouseButtonUp(0)) { HandleInput(mouseId, TouchPhase.Ended, mousePos, mousePos - lastMousePos, temp.force, temp.maxforce, temp.radius, temp.radiusTolerance); } else if (Input.GetMouseButton(0)) { var delta = mousePos - lastMousePos; if (delta != Vector2.zero) { HandleInput(mouseId, TouchPhase.Moved, mousePos, delta, temp.force, temp.maxforce, temp.radius, temp.radiusTolerance); } else { HandleInput(mouseId, TouchPhase.Stationary, mousePos, delta, temp.force, temp.maxforce, temp.radius, temp.radiusTolerance); } } else { return; } lastMousePos = Input.mousePosition; if (GetComponent <StatusUI>()) //this is only required for StatusUI. { GetComponent <StatusUI>().currentInput = 2; } } }
/* * Refresh touch data. */ public void Update() { if (GetComponent <LegacyStatusUI>()) //this is only required for StatusUI. { GetComponent <LegacyStatusUI>().currentInput = -1; } if (useNativeTouches) //this will give false for all platforms except iOS. On iOS it will give true if StartTracking was called. { /* * If you don't need to handle touch state, you can simply replace the code bellow with the following code: * touches.Clear(); * * touches.AddRange(nativeTouches); * * if (GetComponent<StatusUI>()) //this is only required for StatusUI. * GetComponent<StatusUI>().currentInput = 1; */ UpdateNativeTouches(); var nativeTouches = ForceTouchPlugin.GetNativeTouches(); for (var i = 0; i < nativeTouches.Count; i++) { HandleNativeInput(nativeTouches[i]); } if (GetComponent <LegacyStatusUI>()) //this is only required for StatusUI. { GetComponent <LegacyStatusUI>().currentInput = 1; } } else if (Input.touchCount > 0) //if native touch isn't available fallback to unity touch { touches.Clear(); for (int i = 0; i < Input.touchCount; i++) { var t = Input.touches [i]; HandleInput(t.fingerId, t.phase, t.position, t.deltaPosition, t.GetForce(), t.GetMaxForce(), t.GetRadius(), t.GetRadiusTolerance()); } if (GetComponent <LegacyStatusUI>()) //this is only required for StatusUI. { GetComponent <LegacyStatusUI>().currentInput = 2; } } else //if unity touch is unavailable fallback to mouse input { touches.Clear(); var temp = new NativeTouchExtraData(); var mousePos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); if (Input.GetMouseButtonDown(0)) { HandleInput(mouseId, TouchPhase.Began, mousePos, Vector2.zero, temp.force, temp.maxforce, temp.radius, temp.radiusTolerance); } else if (Input.GetMouseButtonUp(0)) { HandleInput(mouseId, TouchPhase.Ended, mousePos, mousePos - lastMousePos, temp.force, temp.maxforce, temp.radius, temp.radiusTolerance); } else if (Input.GetMouseButton(0)) { var delta = mousePos - lastMousePos; if (delta != Vector2.zero) { HandleInput(mouseId, TouchPhase.Moved, mousePos, delta, temp.force, temp.maxforce, temp.radius, temp.radiusTolerance); } else { HandleInput(mouseId, TouchPhase.Stationary, mousePos, delta, temp.force, temp.maxforce, temp.radius, temp.radiusTolerance); } } else { return; } lastMousePos = Input.mousePosition; if (GetComponent <LegacyStatusUI>()) //this is only required for StatusUI. { GetComponent <LegacyStatusUI>().currentInput = 3; } } }