void CenterToggleOnRect(Toggle toggle) { RectTransform toggleRectTransform = toggle.GetComponent <RectTransform>(); RectTransform rectTransform = gameObject.GetComponent <RectTransform>(); CarouselToggler carousel = gameObject.GetComponent <CarouselToggler>(); ScrollRect scrollRect = gameObject.GetComponent <ScrollRect>(); Vector3 diff = GetWorldCenter(rectTransform) - GetWorldCenter(toggleRectTransform); diff = contentRectTransform.InverseTransformVector(diff); if (carousel.horizontalWrap && scrollRect.horizontal) { if (Mathf.Abs(diff[0]) > Mathf.Abs(scrollRect.content.rect.height - Mathf.Abs(diff[0]) - rectTransform.rect.height)) { diff[0] = -1 * Mathf.Sign(diff[0]) * Mathf.Abs(scrollRect.content.rect.height - Mathf.Abs(diff[0]) - rectTransform.rect.height); } } if (carousel.verticalWrap && scrollRect.vertical) { if (Mathf.Abs(diff[1]) > Mathf.Abs(scrollRect.content.rect.height - Mathf.Abs(diff[1]) - rectTransform.rect.height)) { diff[1] = -1 * Mathf.Sign(diff[1]) * Mathf.Abs(scrollRect.content.rect.height - Mathf.Abs(diff[1]) - rectTransform.rect.height); } } Vector2 currentPosition = contentRectTransform.anchoredPosition; targetPosition.Set( scrollRect.horizontal ? currentPosition.x + (diff[0]) : currentPosition.x, scrollRect.vertical ? currentPosition.y + (diff[1]) : currentPosition.y ); startingPosition.Set(currentPosition.x, currentPosition.y); movingToPosition = true; currentProgress = 0; targetToggle = toggle; }
void Start() { carouselToggler = gameObject.GetComponent <CarouselToggler> (); ScrollRect scrollRect = gameObject.GetComponent <ScrollRect> (); content = scrollRect.content; StartCoroutine(WaitInactiveCycleAndReset()); }
void Start () { carouselToggler = gameObject.GetComponent<CarouselToggler> (); ScrollRect scrollRect = gameObject.GetComponent<ScrollRect> (); content = scrollRect.content; Toggle[] toggles = content.GetComponentsInChildren<Toggle> (); lastToggle = toggles [0]; StartCoroutine (WaitInactiveCycleAndReset()); }