Vector2 SnapOutTarget(RectTransform content, SnapDir dir, float offsetRate) { if (dir == SnapDir.left) { return(content.anchoredPosition + Vector2.left * (DistanceToLeft(content) + content.rect.width + canvasWidth * offsetRate)); } else if (dir == SnapDir.right) { return(content.anchoredPosition + Vector2.right * (DistanceToRight(content) + content.rect.width + canvasWidth * offsetRate)); } else if (dir == SnapDir.up) { return(content.anchoredPosition + Vector2.up * (DistanceToUp(content) + content.rect.height + canvasHeight * offsetRate)); } else if (dir == SnapDir.down) { return(content.anchoredPosition + Vector2.down * (DistanceToDown(content) + content.rect.height + canvasHeight * offsetRate)); } else { throw new System.Exception("Invalid direction"); } }
void SnapOut(RectTransform content, SnapDir dir, AnimationCurve curve, float offsetRate = 0) { Vector2 target = SnapOutTarget(content, dir, offsetRate); StartCoroutine(Animate(content, target, curve)); }
void SnapOut(RectTransform content, SnapDir dir, AnimationCurve curve, UnityEvent OnSnapEnd, float offsetRate = 0) { Vector2 target = SnapOutTarget(content, dir, offsetRate); StartCoroutine(AnimateWithEvent(content, target, curve, OnSnapEnd)); }
void Snap(RectTransform content, SnapDir dir, float offsetRate = 0) { Vector2 target = SnapTarget(content, dir, offsetRate); StartCoroutine(Animate(content, target, defaultCurve)); }