public void MyUpdate() { MicroTouch[] mts = MicroTouch.GatherMicroTouches(); foreach (ProximityButton pb in pbses) { pb.prevFingerDown = pb.fingerDown; pb.fingerDown = false; } foreach (MicroTouch t in mts) { Vector2 pos = new Vector2(t.position.x, Screen.height - t.position.y); ProximityButton pbClosest = null; float distClosest = 0; foreach (ProximityButton pb in pbses) { float distance = Vector3.Distance(pb.position, pos); if (distance < diameter) { if ((pbClosest == null) || (distance < distClosest)) { pbClosest = pb; distClosest = distance; } } } if (pbClosest != null) { pbClosest.fingerDown = true; } } }
public static MicroTouch[] GatherMicroTouches() { bool includeMouse = false; switch (Application.platform) { case RuntimePlatform.WindowsEditor: case RuntimePlatform.WindowsPlayer: case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: case RuntimePlatform.WebGLPlayer: if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { includeMouse = true; } break; } int numTouches = Input.touches.Length; if (includeMouse) { numTouches++; } MicroTouch[] mts = new MicroTouch[numTouches]; int n = 0; if (includeMouse) { MicroTouch mt = new MicroTouch(); mt.fingerId = -99; mt.position = Input.mousePosition; mt.phase = TouchPhase.Moved; if (Input.GetMouseButtonDown(0)) { mt.phase = TouchPhase.Began; } if (Input.GetMouseButtonUp(0)) { mt.phase = TouchPhase.Ended; } mts[n++] = mt; } foreach (Touch t in Input.touches) { MicroTouch mt = new MicroTouch(); mt.fingerId = t.fingerId; mt.position = t.position; mt.phase = t.phase; mts[n++] = mt; } return(mts); }
void Update() { output = Vector3.zero; outputRaw = Vector3.zero; if (Time.timeScale == 0) { return; } bool fingerDownNext = false; MicroTouch[] mts = MicroTouch.GatherMicroTouches(); foreach (MicroTouch t in mts) { Vector2 pos = new Vector2(t.position.x, Screen.height - t.position.y); if (r_downable.Contains(pos)) { if (!fingerDown) { if (t.phase == TouchPhase.Began) { beganTime = Time.time; fingerDown = true; fingerDownNext = true; fingerId = t.fingerId; v2down = pos; r_button_ring.x = v2down.x - r_button_ring.width / 2; r_button_ring.y = v2down.y - r_button_ring.height / 2; r_button_finger.x = pos.x - r_button_finger.width / 2; r_button_finger.y = pos.y - r_button_finger.height / 2; UpdatePosition(pos); CheckConstraints(); } } } if (fingerDown) { if (t.fingerId == fingerId) { if ((t.phase == TouchPhase.Ended) || (t.phase == TouchPhase.Canceled)) { if (Time.time - beganTime < 0.2f) { detectedTap = true; } } else { fingerDownNext = true; UpdatePosition(pos); r_button_finger.x = pos.x - r_button_finger.width / 2; r_button_finger.y = pos.y - r_button_finger.height / 2; CheckConstraints(); } } } } OverlayStandardInputAxes(); fingerDown = fingerDownNext; }