// ----------------- public int HitTest(List <TouchControl> controlList, Vector2 screenPos, Camera cam, int maxHits = 8, float fingerRadPx = 0, TouchControlFilterFunc filter = null) { if (maxHits < 1) { maxHits = 1; } this.Clear(); this.EnsureCapacity(maxHits); for (int ci = 0; ci < controlList.Count; ++ci) { TouchControl c = controlList[ci]; if ((c == null) || ((filter != null) && !filter(c))) { continue; } if (!c.HitTest(screenPos, cam, fingerRadPx, this.tempHit)) { continue; } int insertPos = -1; for (int ti = 0; ti < this.GetList().Count; ++ti) { if (this.tempHit.IsHigherThan(this.GetList()[ti])) { insertPos = ti; break; } } // Add new hit to the list... if (this.GetUsedCount() < maxHits) { this.GetNewObject(insertPos).CopyFrom(this.tempHit); } // If the list is fulll recycle the last hit... else if (insertPos >= 0) { Hit lastHit = this.GetList()[maxHits - 1]; this.GetList().RemoveAt(maxHits - 1); this.GetList().Insert(insertPos, lastHit); lastHit.CopyFrom(this.tempHit); } } return(this.GetUsedCount()); }
// ------------------- public void CopyFrom(Hit b) { this.c = b.c; this.depth = b.depth; this.indirectHit = b.indirectHit; this.localPos = b.localPos; this.closestLocalPos = b.closestLocalPos; this.screenPos = b.screenPos; this.closestScreenPos = b.closestScreenPos; this.screenDistSqPx = b.screenDistSqPx; }
// --------------------- public bool CanAcceptControl(TouchControl c) { for (int i = 0; i < this.controls.Count; ++i) { TouchControl a = this.controls[i]; if ((a != null) && !a.CanShareTouchWith(c)) return false; } return true; }
// ------------------ override public void ReleaseAllTouches() { for (int i = 0; i < this.targetControlList.Count; ++i) { TouchControl c = this.targetControlList[i]; if (c != null) { c.ReleaseAllTouches(); } } }
// ----------------- static public int CompareByDepth(TouchControl a, TouchControl b) { if ((a == null) || (b == null)) { return(((a == null) && (b == null)) ? 0 : (a == null) ? 1 : -1); } float za = a.transform.position.z; float zb = a.transform.position.z; return((Mathf.Abs(za - zb) < 0.001f) ? 0 : (za < zb) ? -1 : 1); }
// -------------------- public void RemoveControl(TouchControl c) { if (!this.CanBeUsed()) { return; } if (this.controls != null) { this.controls.Remove(c); } }
// ----------------- public void Move(Vector2 screenPos, Camera cam) { this.cam = cam; this.screenPosCur = screenPos; // Send Move event to controls controlled by this touch... for (int i = 0; i < this.controls.Count; ++i) { TouchControl a = this.controls[i]; if ((a != null)) a.OnTouchMove(this); } }
// -------------------- public void ReleaseControl(TouchControl c, TouchControl.TouchEndType touchEndType) //bool cancel) { int i = this.controls.IndexOf(c); if (i < 0) { return; } c.OnTouchEnd(this, touchEndType); //cancel); this.controls.RemoveAt(i); this.OnControlListChange(); }
//! \cond // --------------------- public void AddControl(TouchControl c) { if (!this.CanBeUsed()) { return; } if (this.controls.Contains(c)) { #if UNITY_EDITOR Debug.LogError("Ctrl(" + this.name + ") already contains " + ((c != null) ? c.name : "NULL")); #endif return; } this.controls.Add(c); }
// ------------------ override public bool OnTouchStart(TouchObject touchObj, TouchControl sender, TouchStartType touchStartType) { if (this.touchObj != null) { return(false); } this.touchObj = touchObj; this.touchStartType = touchStartType; this.touchObj.AddControl(this); Vector2 localPos = this.ScreenToOrientedPos(touchObj.screenPosStart, touchObj.cam); this.touchState.OnTouchStart(localPos, localPos, 0, touchObj.IsMouse()); return(true); }
// ------------------- public void AddControl(TouchControl c) { if (c == null) return; if (this.controls.Contains(c)) { #if UNITY_EDITOR Debug.LogError("TouchControl [" + c.name + "] is already assigned to a Touch!!"); #endif return; } this.controls.Add(c); this.OnControlListChange(); }
// ------------------ public void SetPressure(float rawPressure, float maxPressure) { this.isPressureSensitive = true; //this.rawPressure = rawPressure; //this.rawMaxPressure = maxPressure; this.normalizedPressure = (maxPressure < 0.001f) ? 1.0f : (rawPressure / maxPressure); // Send Move event to controls controlled by this touch... for (int i = 0; i < this.controls.Count; ++i) { TouchControl a = this.controls[i]; if ((a != null)) { a.OnTouchPressureChange(this); } } }
// -------------- override public bool OnTouchStart(TouchObject touch, TouchControl sender, TouchStartType touchStartType) { bool someActivated = false; for (int i = 0; i < this.targetControlList.Count; ++i) { TouchControl c = this.targetControlList[i]; if (c != null) { if (c.OnTouchStart(touch, this, TouchStartType.ProxyPress)) { someActivated = true; } } } return(someActivated); }
// ------------------ override public bool OnTouchStart(TouchObject touchObj, TouchControl sender, TouchStartType touchStartType) { if (this.touchObj != null) { return(false); } //Debug.LogFormat("----------------Track pad start : {0} : active:{1}", Time.frameCount, this.IsActive()); this.touchObj = touchObj; this.touchStartType = touchStartType; this.touchObj.AddControl(this); Vector2 localPos = this.ScreenToOrientedPos(touchObj.screenPosStart, touchObj.cam); this.touchState.OnTouchStart(localPos, localPos, 0, touchObj); return(true); }
// ------------------ public bool HitTestAny(List <TouchControl> controlList, Vector2 screenPos, Camera cam, float fingerRadPx = 0, TouchControlFilterFunc filter = null) { this.EnsureCapacity(1); this.Clear(); for (int i = 0; i < controlList.Count; ++i) { TouchControl c = controlList[i]; if ((c == null) || ((filter != null) && !filter(c))) { continue; } if (c.HitTest(screenPos, cam, fingerRadPx, this.tempHit)) { this.GetNewObject().CopyFrom(this.tempHit); return(true); } } return(false); }
// ------------------- protected Vector3 ClampInsideOther(Vector3 targetWorldPos, TouchControl limiter) { Rect localRect = this.GetLocalRect(); Rect limiterRect = limiter.GetLocalRect(); Matrix4x4 localToLimiterSpace = limiter.transform.worldToLocalMatrix * CFUtils.ChangeMatrixTranl(this.transform.localToWorldMatrix, targetWorldPos); bool thisIsRound = ((this.shape == Shape.Circle) || (this.shape == Shape.Ellipse)); bool limiterIsRound = ((limiter.shape == Shape.Circle) || (limiter.shape == Shape.Ellipse)); Rect rectInLimiterSpace = CFUtils.TransformRect(localRect, localToLimiterSpace, thisIsRound); Vector2 localOfs = CFUtils.ClampRectInside(rectInLimiterSpace, thisIsRound, limiterRect, limiterIsRound); if (localOfs == Vector2.zero) { return(targetWorldPos); } return(targetWorldPos + limiter.transform.localToWorldMatrix.MultiplyVector(localOfs)); }
// ------------------- override public bool CanBeTouchedDirectly(TouchObject touchObj) { if (!base.CanBeTouchedDirectly(touchObj)) { return(false); } for (int i = 0; i < this.targetControlList.Count; ++i) { TouchControl c = this.targetControlList[i]; if (c == null) { continue; } if (c.CanBeActivatedByOtherControl(this, touchObj)) { return(true); } } return(false); }
// ------------------- override public bool CanBeActivatedByOtherControl(TouchControl c, TouchObject touchObj) { return(base.CanBeActivatedByOtherControl(c, touchObj) && (this.touchObj == null)); }
// ---------------------- virtual public bool CanBeActivatedByOtherControl(TouchControl c, TouchObject touchObj) { return(this.IsActive()); }
// -------------------- virtual public bool CanShareTouchWith(TouchControl c) { return(true); }
//! \cond abstract public bool OnTouchStart(TouchObject touch, TouchControl sender, TouchStartType touchStartType);
// ---------------- public bool SwipeOverFromNothingControlFilter(TouchControl c) { return((c != null) && c.CanBeSwipedOverFromNothing(this)); }
// --------------- public bool DirectTouchControlFilter(TouchControl c) { return((c != null) && c.CanBeTouchedDirectly(this)); }
// ----------------- public void Reset() { this.c = null; }
// ---------------------- 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; } } } } } }
// --------------------- private bool RaycastControlFilter(TouchControl c) { return((c != null) && c.CanBeTouchedDirectly(null)); }
// ------------------- override public bool CanBeActivatedByOtherControl(TouchControl c, TouchObject touchObj) { return(base.CanBeActivatedByOtherControl(c, touchObj) && (this.targetControl != null) && this.targetControl.CanBeActivatedByDynamicRegion()); }