// -------------- private SystemTouch StartNewTouch(SystemTouchEventData data) { SystemTouch newTouch = null; for (int i = 0; i < this.touchList.Count; ++i) { SystemTouch t = this.touchList[i]; if (!t.touch.IsOn()) { newTouch = t; } else if (t.hwId == data.id) { #if UNITY_EDITOR // Debug.LogWarning("[" + Time.frameCount + "] System tries to start a duplicate touch (" + data.id + ")! Ending the old one (started at frame: " + t.startFrame + ")."); #endif t.touch.End(true); } } if (newTouch != null) { newTouch.elapsedSinceLastAction = 0; newTouch.hwId = data.id; newTouch.startFrame = Time.frameCount; newTouch.touch.Start(data.pos, data.pos, data.cam, data.isMouseEvent); return(newTouch); } return(null); }
// ------------------- public void OnSystemTouchStart(SystemTouchEventData data) { if (!this.IsInitialized) { return; } if (this.rig != null) { this.rig.WakeTouchControlsUp(); } SystemTouch t = this.StartNewTouch(data); if (t == null) { return; } this.Prepare(); if (this.hitPool.HitTest(this.controls, data.pos, data.cam, MAX_RAYCAST_HITS, this.fingerRadInPx, t.touch.DirectTouchControlFilter) > 0) { for (int i = 0; i < this.hitPool.GetList().Count; ++i) { TouchControl.Hit hit = this.hitPool.GetList()[i]; if ((hit == null) || (hit.c == null)) { continue; } // If this touch is already shared by other controls... if (hit.c.dontAcceptSharedTouches && (t.touch.GetControlCount() > 0)) { continue; } if (hit.c.OnTouchStart(t.touch, null, TouchControl.TouchStartType.DirectPress)) { // Stop sharing this touch if a control doesn't allow it... if (!hit.c.shareTouch) { break; } } else { } } } else { } }
// ---------------------- public void OnSystemTouchEnd(SystemTouchEventData data) { if (!this.IsInitialized) { return; } if (this.rig != null) { this.rig.WakeTouchControlsUp(); } SystemTouch t = this.FindTouch(data.id); if (t == null) { return; } t.touch.End(false); }
// ---------------------- public void OnSystemTouchMove(SystemTouchEventData data) { if (!this.IsInitialized) { return; } if (this.rig != null) { this.rig.WakeTouchControlsUp(); } SystemTouch t = this.FindTouch(data.id); if (t == null) { return; } t.WakeUp(); Vector2 pos = data.pos; #if UNITY_EDITOR mSkipTouchScreenPixels = Mathf.Clamp(mSkipTouchScreenPixels, 0, 10); if (mSkipTouchScreenPixels > 0) { pos.x = (float)((mSkipTouchScreenPixels + 1) * (Mathf.RoundToInt(pos.x) / (mSkipTouchScreenPixels + 1))); pos.y = (float)((mSkipTouchScreenPixels + 1) * (Mathf.RoundToInt(pos.y) / (mSkipTouchScreenPixels + 1))); } #endif t.touch.Move(pos, data.cam); // Handle swipe over... List <TouchControl> restrictedSwipeOverTargetList = t.touch.GetRestrictedSwipeOverTargetList(); List <TouchControl> swipeOverTargetList = ((restrictedSwipeOverTargetList != null) ? restrictedSwipeOverTargetList : this.controls); if ((swipeOverTargetList.Count > 0) && (this.hitPool.HitTest(swipeOverTargetList, t.touch.screenPosCur, t.touch.cam, MAX_RAYCAST_HITS, 0) > 0)) { for (int ci = 0; ci < this.hitPool.GetList().Count; ++ci) { TouchControl c = this.hitPool.GetList()[ci].c; if (!c.IsActive()) { continue; } if ((restrictedSwipeOverTargetList == null) ? c.CanBeSwipedOverFromNothing(t.touch) : c.CanBeSwipedOverFromRestrictedList(t.touch)) { if (c.OnTouchStart(t.touch, null, TouchControl.TouchStartType.SwipeOver)) { if (!c.shareTouch) { break; } } } } } }