// ------------------- 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)); }
// ---------------------- protected Vector3 ClampInsideCanvas(Vector3 targetWorldPos, Canvas limiterCanvas) { RectTransform canvasTr = null; if ((limiterCanvas == null) || ((canvasTr = (limiterCanvas.transform as RectTransform)) == null)) { return(targetWorldPos); } Rect localRect = this.GetLocalRect(); Rect limiterRect = canvasTr.rect; Matrix4x4 localToLimiterSpace = limiterCanvas.transform.worldToLocalMatrix * CFUtils.ChangeMatrixTranl(this.transform.localToWorldMatrix, targetWorldPos); bool thisIsRound = ((this.shape == Shape.Circle) || (this.shape == Shape.Ellipse)); Rect rectInLimiterSpace = CFUtils.TransformRect(localRect, localToLimiterSpace, thisIsRound); Vector2 localOfs = CFUtils.ClampRectInside(rectInLimiterSpace, thisIsRound, limiterRect, false); if (localOfs == Vector2.zero) { return(targetWorldPos); } return(targetWorldPos + limiterCanvas.transform.localToWorldMatrix.MultiplyVector(localOfs)); }