/// <summary> /// Update all the trackers available and find and kill any unused ones. /// </summary> private void UpdateTrackers() { // Set all trackers to be killed, if they arent picked up again during the frame, they arnt being used. foreach (InputTracker tracker in _trackers) { tracker.KillTracker(); } if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) { //update or start trackers. int i = 0, l = UnityEngine.Input.touchCount; for (; i < l; ++i) { Touch t = UnityEngine.Input.GetTouch(i); // try to get our tracker for this finger id InputTracker tracker = _trackerLookup.ContainsKey(t.fingerId) ? _trackerLookup[t.fingerId] : null; if (tracker != null) { tracker.UpdateTracker(t.position); } else { tracker = BeginTracking(t.fingerId, t.position); } } } else { // try to get our tracker for the mouse or simulated second finger. InputTracker tracker = null; if (UnityEngine.Input.GetMouseButton(0)) { tracker = _trackerLookup.ContainsKey(0) ? _trackerLookup[0] : null; if (tracker != null) { tracker.UpdateTracker(UnityEngine.Input.mousePosition); } else { tracker = BeginTracking(0, UnityEngine.Input.mousePosition); } } tracker = null; if (UnityEngine.Input.GetKey(KeyCode.LeftCommand) || UnityEngine.Input.GetKey(KeyCode.LeftControl)) { tracker = _trackerLookup.ContainsKey(1) ? _trackerLookup[1] : null; if (tracker != null) { tracker.UpdateTracker(_secondaryMouseStartPosition - (UnityEngine.Input.mousePosition - _secondaryMouseStartPosition)); } else { _secondaryMouseStartPosition = UnityEngine.Input.mousePosition - Vector3.right * 50; tracker = BeginTracking(1, _secondaryMouseStartPosition - Vector3.right * 50); } } } }