public void JumpTo(RectTransformPosition position) { var lockedPosition = position.WithLockedAxes(transform, _lockHorizontal, _lockVertical); transform.MoveAnchorsKeepPosition(lockedPosition.anchorMin, lockedPosition.anchorMax); transform.SetOffsets(lockedPosition.offsetMin, lockedPosition.offsetMax); }
public void MoveTo(RectTransformPosition position, float?time = null) { if (!Application.isPlaying || singleCoroutine == null || !gameObject.activeInHierarchy || (time ?? defaultMoveTime) <= 0) { JumpTo(position); } else { singleCoroutine.Start(DoMoveTo(position.WithLockedAxes(transform, _lockHorizontal, _lockVertical), time ?? defaultMoveTime)); } }
private IEnumerator DoMoveTo(RectTransformPosition position, float time) { transform.MoveAnchorsKeepPosition(position.anchorMin, position.anchorMax); if (time > 0) { var timeCoefficient = 1 / time; for (var timeProgress = 0f; timeProgress < 1; timeProgress += timeCoefficient * Time.deltaTime) { transform.LerpToOffsets(position.offsetMin, position.offsetMax, timeProgress); yield return(null); } } transform.SetOffsets(position.offsetMin, position.offsetMax); }