< Summary

Class:CarouselComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Carousel/CarouselComponentView.cs
Covered lines:201
Uncovered lines:63
Coverable lines:264
Total lines:706
Line coverage:76.1% (201 of 264)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CarouselComponentView()0%110100%
Awake()0%110100%
Start()0%220100%
Configure(...)0%110100%
RefreshControl()0%22090.91%
OnScreenSizeChanged()0%110100%
Dispose()0%110100%
SetSpaceBetweenItems(...)0%2.032080%
SetTimeBetweenItems(...)0%110100%
SetAnimationTransitionTime(...)0%110100%
SetAnimationCurve(...)0%110100%
SetBackgroundColor(...)0%2.262060%
SetManualControlsActive()0%2100%
SetManualControlsActive(...)0%6.076087.5%
OnFocus()0%20400%
OnLoseFocus()0%64050%
SetItems(...)0%6200%
SetItems(...)0%220100%
AddItemWithDotsSelector(...)0%110100%
AddItem(...)0%110100%
RemoveItem(...)0%220100%
GetItems()0%110100%
ExtractItems()0%330100%
RemoveItems()0%110100%
StartCarousel(...)0%220100%
StopCarousel()0%220100%
GoToPreviousItem()0%2.062075%
ResetCarousel()0%2100%
GoToNextItem()0%2.062075%
MakeJumpFromDotsSelector(...)0%2.062075%
ConfigureManualButtonsEvents()0%330100%
CreateItem(...)0%2.012088.89%
ResizeItem(...)0%110100%
ResizeAllItems()0%5.935066.67%
DestroyInstantiatedItems()0%330100%
RunCarouselCoroutine()0%34.4618062.96%
RunRightAnimation()0%8.125050%
RunLeftAnimation()0%8.125050%
RunAnimationCoroutine()0%5.735069.23%
GenerateDotsSelector()0%660100%
SetSelectedDot(...)0%550100%
CleanInstantiatedItems()0%2100%
ResetManualCarousel()0%2100%
RegisterCurrentInstantiatedItems()0%6.026092.31%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/Carousel/CarouselComponentView.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8public interface ICarouselComponentView
 9{
 10    /// <summary>
 11    /// Set the distance between carousel items.
 12    /// </summary>
 13    /// <param name="newSpace">Distance between items.</param>
 14    void SetSpaceBetweenItems(float newSpace);
 15
 16    /// <summary>
 17    /// Set the time that will be pass between carousel items.
 18    /// </summary>
 19    /// <param name="newTime">Time between items.</param>
 20    void SetTimeBetweenItems(float newTime);
 21
 22    /// <summary>
 23    /// Set the time that will be pass during the transition between items.
 24    /// </summary>
 25    /// <param name="newTime">Transition time between items.</param>
 26    void SetAnimationTransitionTime(float newTime);
 27
 28    /// <summary>
 29    /// Set the animation curve that will be used for the animation between items.
 30    /// </summary>
 31    /// <param name="newCurve">Animation curve between items.</param>
 32    void SetAnimationCurve(AnimationCurve newCurve);
 33
 34    /// <summary>
 35    /// Set the color of the carousel background.
 36    /// </summary>
 37    /// <param name="newColor">Background color.</param>
 38    void SetBackgroundColor(Color newColor);
 39
 40    /// <summary>
 41    /// Activates/Deactivates the controls to go to the next/previous item manually.
 42    /// </summary>
 43    /// <param name="isActived">True for activating the manual controls.</param>
 44    void SetManualControlsActive(bool isActived);
 45
 46    /// <summary>
 47    /// Set the items of the carousel.
 48    /// </summary>
 49    /// <param name="items">List of UI components.</param>
 50    void SetItems(List<BaseComponentView> items);
 51
 52    /// <summary>
 53    /// Creates the items of the carousel from the prefab. All previously existing items will be removed.
 54    /// </summary>
 55    /// <param name="prefab">Prefab to create items</param>
 56    /// <param name="amountOfItems">Amounts of items to be created</param>
 57    void SetItems(BaseComponentView prefab, int amountOfItems);
 58
 59    /// <summary>
 60    /// Adds a new item in the carousel.
 61    /// </summary>
 62    /// <param name="item">An UI component.</param>
 63    void AddItem(BaseComponentView item);
 64
 65    /// <summary>
 66    /// Adds a new item in the carousel and update carousel dot selector.
 67    /// </summary>
 68    /// <param name="item">An UI component.</param>
 69    void AddItemWithDotsSelector(BaseComponentView item);
 70
 71    /// <summary>
 72    /// Remove an item from the carousel.
 73    /// </summary>
 74    /// <param name="item">An UI component</param>
 75    void RemoveItem(BaseComponentView item);
 76
 77    /// <summary>
 78    /// Get all the items of the carousel.
 79    /// </summary>
 80    /// <returns>The list of items.</returns>
 81    List<BaseComponentView> GetItems();
 82
 83    /// <summary>
 84    /// Extract all items out of the carousel.
 85    /// </summary>
 86    /// <returns>The list of extracted items.</returns>
 87    List<BaseComponentView> ExtractItems();
 88
 89    /// <summary>
 90    /// Remove all existing items from the carousel.
 91    /// </summary>
 92    void RemoveItems();
 93
 94    /// <summary>
 95    /// Start carousel animation.
 96    /// </summary>
 97    /// <param name="fromIndex">It specifies from where item the carousel will start.</param>
 98    /// <param name="startInmediately">True to directly execute the first transition.</param>
 99    /// <param name="direction">Set the direction of the carousel animations: right or left.</param>
 100    /// <param name="changeDirectionAfterFirstTransition">True to change the carousel direction just after the first tra
 101    /// <param name="numberOfInitialJumps">Number of jumps that will be executed in the first transition.</param>
 102    void StartCarousel(int fromIndex, bool startInmediately, CarouselDirection direction, bool changeDirectionAfterFirst
 103
 104    /// <summary>
 105    /// Stop carousel animation.
 106    /// </summary>
 107    void StopCarousel();
 108
 109    /// <summary>
 110    /// Force the carousel to show the previous item.
 111    /// </summary>
 112    void GoToPreviousItem();
 113
 114    /// <summary>
 115    /// Force the carousel to show the next item.
 116    /// </summary>
 117    void GoToNextItem();
 118
 119    /// <summary>
 120    /// Force the carousel to jump to a specific item.
 121    /// </summary>
 122    /// <param name="numberOfJumps">Number of jumps that will be executed during the transition.</param>
 123    /// <param name="direction">Direction in which to make the jumps.</param>
 124    void MakeJumpFromDotsSelector(int numberOfJumps, CarouselDirection direction);
 125}
 126
 127public enum CarouselDirection
 128{
 129    Right,
 130    Left
 131}
 132
 133public class CarouselComponentView : BaseComponentView, ICarouselComponentView, IComponentModelConfig<CarouselComponentM
 134{
 135    [Header("Prefab References")]
 136    [SerializeField] internal RectTransform itemsContainer;
 137    [SerializeField] internal HorizontalLayoutGroup horizontalLayout;
 138    [SerializeField] internal ScrollRect itemsScroll;
 139    [SerializeField] internal RectTransform viewport;
 140    [SerializeField] internal Image background;
 141    [SerializeField] internal Button previousButton;
 142    [SerializeField] internal Button nextButton;
 143    [SerializeField] internal HorizontalLayoutGroup dotsSelector;
 144    [SerializeField] internal Button dotButtonTemplate;
 145    [SerializeField] internal Color dotSelectedColor;
 146    [SerializeField] internal Color dotUnselectedColor;
 147    [SerializeField] internal bool showOnFocus = false;
 148
 149    [Header("Configuration")]
 150    [SerializeField] internal CarouselComponentModel model;
 151
 155152    internal List<BaseComponentView> instantiatedItems = new List<BaseComponentView>();
 153    internal Coroutine itemsCoroutine;
 154    internal int currentItemIndex = 0;
 155    internal int currentDotIndex = 0;
 156    internal float currentFinalNormalizedPos;
 157    internal bool isInTransition = false;
 158
 159    public override void Awake()
 160    {
 142161        base.Awake();
 162
 142163        StartCoroutine(RegisterCurrentInstantiatedItems());
 142164        ConfigureManualButtonsEvents();
 142165    }
 166
 167    public override void Start()
 168    {
 73169        if (model.automaticTransition)
 73170            StartCarousel();
 73171    }
 172
 173    public void Configure(CarouselComponentModel newModel)
 174    {
 1175        model = newModel;
 1176        RefreshControl();
 1177    }
 178
 179    public override void RefreshControl()
 180    {
 1181        if (model == null)
 0182            return;
 183
 1184        SetSpaceBetweenItems(model.spaceBetweenItems);
 1185        SetTimeBetweenItems(model.timeBetweenItems);
 1186        SetAnimationTransitionTime(model.animationTransitionTime);
 1187        SetAnimationCurve(model.animationCurve);
 1188        SetBackgroundColor(model.backgroundColor);
 1189        SetManualControlsActive(model.showManualControls);
 1190        ResizeAllItems();
 1191        GenerateDotsSelector();
 1192    }
 193
 194    public override void OnScreenSizeChanged()
 195    {
 26196        base.OnScreenSizeChanged();
 197
 26198        ResizeAllItems();
 26199    }
 200
 201    public override void Dispose()
 202    {
 424203        base.Dispose();
 204
 424205        StopCarousel();
 424206        DestroyInstantiatedItems();
 424207    }
 208
 209    public void SetSpaceBetweenItems(float newSpace)
 210    {
 2211        model.spaceBetweenItems = newSpace;
 212
 2213        if (horizontalLayout == null)
 0214            return;
 215
 2216        horizontalLayout.spacing = newSpace;
 2217    }
 218
 219    public void SetTimeBetweenItems(float newTime)
 220    {
 2221        model.timeBetweenItems = newTime;
 2222    }
 223
 224    public void SetAnimationTransitionTime(float newTime)
 225    {
 2226        model.animationTransitionTime = newTime;
 2227    }
 228
 229    public void SetAnimationCurve(AnimationCurve newCurve)
 230    {
 2231        model.animationCurve = newCurve;
 2232    }
 233
 234    public void SetBackgroundColor(Color newColor)
 235    {
 2236        model.backgroundColor = newColor;
 237
 2238        if (background == null)
 2239            return;
 240
 0241        background.color = newColor;
 0242    }
 243
 244    public void SetManualControlsActive() =>
 0245        SetManualControlsActive(model.showManualControls);
 246
 247    public void SetManualControlsActive(bool isActived)
 248    {
 738249        model.showManualControls = isActived;
 250
 738251        if (previousButton == null || nextButton == null)
 0252            return;
 253
 738254        int currentNumberOfItems = itemsContainer.childCount;
 738255        previousButton.gameObject.SetActive(isActived && currentNumberOfItems > 1);
 738256        nextButton.gameObject.SetActive(isActived && currentNumberOfItems > 1);
 738257        dotsSelector.gameObject.SetActive(isActived && currentNumberOfItems > 1);
 738258    }
 259
 260    public override void OnFocus()
 261    {
 0262        base.OnFocus();
 263
 0264        if (previousButton == null || nextButton == null || !showOnFocus)
 0265            return;
 266
 0267        int currentNumberOfItems = itemsContainer.childCount;
 0268        previousButton.gameObject.SetActive(currentNumberOfItems > 1);
 0269        nextButton.gameObject.SetActive(currentNumberOfItems > 1);
 0270    }
 271
 272    public override void OnLoseFocus()
 273    {
 144274        base.OnLoseFocus();
 275
 144276        if (previousButton == null || nextButton == null || !showOnFocus)
 144277            return;
 278
 0279        previousButton.gameObject.SetActive(false);
 0280        nextButton.gameObject.SetActive(false);
 0281    }
 282
 283    public void SetItems(BaseComponentView prefab, int amountOfItems)
 284    {
 0285        DestroyInstantiatedItems();
 286
 0287        for (int i = 0; i < amountOfItems; i++)
 288        {
 0289            BaseComponentView instanciatedItem = Instantiate(prefab);
 0290            CreateItem(instanciatedItem, $"Item{i}");
 291        }
 292
 0293        SetManualControlsActive(model.showManualControls);
 0294        GenerateDotsSelector();
 0295    }
 296
 297    public void SetItems(List<BaseComponentView> items)
 298    {
 15299        DestroyInstantiatedItems();
 300
 92301        for (int i = 0; i < items.Count; i++)
 302        {
 31303            CreateItem(items[i], $"Item{i}");
 304        }
 305
 15306        SetManualControlsActive(model.showManualControls);
 15307        GenerateDotsSelector();
 15308    }
 309
 310    public void AddItemWithDotsSelector(BaseComponentView item)
 311    {
 2312        CreateItem(item, $"Item{instantiatedItems.Count}");
 2313        SetManualControlsActive(model.showManualControls);
 2314        GenerateDotsSelector();
 2315    }
 316
 317    public void AddItem(BaseComponentView item) =>
 6318        CreateItem(item, $"Item{instantiatedItems.Count}");
 319
 320    public void RemoveItem(BaseComponentView item)
 321    {
 2322        BaseComponentView itemToRemove = instantiatedItems.FirstOrDefault(x => x == item);
 1323        if (itemToRemove != null)
 324        {
 1325            Destroy(itemToRemove.gameObject);
 1326            instantiatedItems.Remove(item);
 327        }
 328
 1329        SetManualControlsActive(model.showManualControls);
 1330        GenerateDotsSelector();
 1331    }
 332
 1333    public List<BaseComponentView> GetItems() { return instantiatedItems; }
 334
 335    public List<BaseComponentView> ExtractItems()
 336    {
 590337        List<BaseComponentView> extractedItems = new List<BaseComponentView>();
 1730338        foreach (BaseComponentView item in instantiatedItems)
 339        {
 275340            if (item != null)
 275341                item.transform.SetParent(null);
 342
 275343            extractedItems.Add(item);
 344        }
 345
 590346        instantiatedItems.Clear();
 590347        SetManualControlsActive(model.showManualControls);
 348
 590349        return extractedItems;
 350    }
 351
 352    public void RemoveItems()
 353    {
 110354        DestroyInstantiatedItems();
 110355        SetManualControlsActive(model.showManualControls);
 110356    }
 357
 358    public void StartCarousel(
 359        int fromIndex = 0,
 360        bool startInmediately = false,
 361        CarouselDirection direction = CarouselDirection.Right,
 362        bool changeDirectionAfterFirstTransition = false,
 363        int numberOfInitialJumps = 1)
 364    {
 123365        StopCarousel();
 366
 123367        if (isActiveAndEnabled)
 123368            itemsCoroutine = StartCoroutine(RunCarouselCoroutine(fromIndex, startInmediately, direction, changeDirection
 123369    }
 370
 371    public void StopCarousel()
 372    {
 548373        if (itemsCoroutine == null)
 542374            return;
 375
 6376        StopCoroutine(itemsCoroutine);
 377
 6378        itemsCoroutine = null;
 6379        isInTransition = false;
 6380    }
 381
 382    public void GoToPreviousItem()
 383    {
 2384        if (isInTransition)
 0385            return;
 386
 2387        StartCarousel(
 388            fromIndex: currentItemIndex,
 389            startInmediately: true,
 390            direction: CarouselDirection.Left,
 391            changeDirectionAfterFirstTransition: true,
 392            numberOfInitialJumps: 1);
 2393    }
 394
 395    public void ResetCarousel()
 396    {
 0397        int index = 0;
 0398        SetSelectedDot(index);
 0399    }
 400
 401    public void GoToNextItem()
 402    {
 2403        if (isInTransition)
 0404            return;
 405
 2406        StartCarousel(
 407            fromIndex: currentItemIndex,
 408            startInmediately: true,
 409            direction: CarouselDirection.Right,
 410            changeDirectionAfterFirstTransition: false,
 411            numberOfInitialJumps: 1);
 2412    }
 413
 414    public void MakeJumpFromDotsSelector(int numberOfJumps, CarouselDirection direction)
 415    {
 1416        if (isInTransition)
 0417            return;
 418
 1419        StartCarousel(
 420            fromIndex: currentItemIndex,
 421            startInmediately: true,
 422            direction: direction,
 423            changeDirectionAfterFirstTransition: direction == CarouselDirection.Left,
 424            numberOfInitialJumps: numberOfJumps);
 1425    }
 426
 427    internal void ConfigureManualButtonsEvents()
 428    {
 144429        if (previousButton != null)
 430        {
 144431            previousButton.onClick.RemoveAllListeners();
 144432            previousButton.onClick.AddListener(GoToPreviousItem);
 433        }
 434
 144435        if (nextButton != null)
 436        {
 144437            nextButton.onClick.RemoveAllListeners();
 144438            nextButton.onClick.AddListener(GoToNextItem);
 439        }
 144440    }
 441
 442    internal void CreateItem(BaseComponentView newItem, string name)
 443    {
 40444        if (newItem == null)
 0445            return;
 446
 40447        newItem.transform.SetParent(itemsContainer);
 40448        newItem.transform.localPosition = Vector3.zero;
 40449        newItem.transform.localScale = Vector3.one;
 40450        newItem.name = name;
 451
 40452        instantiatedItems.Add(newItem);
 453
 40454        ResizeItem((RectTransform)newItem.transform);
 40455    }
 456
 457    internal void ResizeItem(RectTransform item)
 458    {
 40459        ((RectTransform)item.transform).sizeDelta = new Vector2(viewport.rect.width, viewport.rect.height);
 460
 40461        int currentNumberOfItems = itemsContainer.childCount;
 40462        itemsContainer.offsetMin = Vector2.zero;
 40463        float extraSpace = (currentNumberOfItems - 1) * model.spaceBetweenItems;
 40464        itemsContainer.offsetMax = new Vector2(viewport.rect.width * (currentNumberOfItems - 1) + extraSpace, 0);
 40465    }
 466
 467    internal void ResizeAllItems()
 468    {
 44469        if (itemsScroll.horizontalNormalizedPosition != 0f)
 0470            itemsScroll.horizontalNormalizedPosition = 0f;
 471
 44472        if (model.automaticTransition)
 44473            StartCarousel();
 474
 88475        foreach (Transform child in itemsContainer)
 476        {
 0477            ResizeItem((RectTransform)child);
 478        }
 44479    }
 480
 481    internal void DestroyInstantiatedItems()
 482    {
 549483        List<BaseComponentView> itemsToDestroy = ExtractItems();
 484
 1632485        foreach (BaseComponentView itemToDestroy in itemsToDestroy)
 486        {
 267487            if (itemToDestroy != null)
 267488                DestroyImmediate(itemToDestroy.gameObject);
 489        }
 490
 549491        itemsToDestroy.Clear();
 492
 549493        instantiatedItems.Clear();
 494
 549495        itemsContainer.offsetMin = Vector2.zero;
 549496        itemsContainer.offsetMax = Vector2.zero;
 549497    }
 498
 499    internal IEnumerator RunCarouselCoroutine(
 500        int fromIndex = 0,
 501        bool startInmediately = false,
 502        CarouselDirection direction = CarouselDirection.Right,
 503        bool changeDirectionAfterFirstTransition = false,
 504        int numberOfInitialJumps = 1)
 505    {
 123506        currentItemIndex = fromIndex;
 123507        SetSelectedDot(currentItemIndex);
 123508        bool continueCarrousel = true;
 123509        while (gameObject.activeInHierarchy && itemsContainer.childCount > 1 && continueCarrousel)
 510        {
 6511            float elapsedTime = 0f;
 512
 6513            if (!startInmediately)
 514            {
 1515                while (elapsedTime < model.timeBetweenItems)
 516                {
 1517                    if (!model.pauseOnFocus || (model.pauseOnFocus && !isFocused))
 1518                        elapsedTime += Time.deltaTime;
 519
 1520                    yield return null;
 521                }
 522
 523            }
 524
 5525            if (instantiatedItems.Count > 0)
 526            {
 5527                if (direction == CarouselDirection.Right)
 528                {
 3529                    SetSelectedDot(currentItemIndex == (instantiatedItems.Count - 1) ? 0 : currentItemIndex + numberOfIn
 3530                    yield return RunRightAnimation(numberOfInitialJumps);
 531
 0532                    if (changeDirectionAfterFirstTransition)
 533                    {
 0534                        direction = CarouselDirection.Left;
 0535                        changeDirectionAfterFirstTransition = false;
 536                    }
 0537                    continueCarrousel = model.automaticTransition;
 538                }
 539                else
 540                {
 2541                    SetSelectedDot(currentItemIndex == 0 ? (instantiatedItems.Count - 1) : currentItemIndex - numberOfIn
 2542                    yield return RunLeftAnimation(numberOfInitialJumps);
 543
 0544                    if (changeDirectionAfterFirstTransition)
 545                    {
 0546                        direction = CarouselDirection.Right;
 0547                        changeDirectionAfterFirstTransition = false;
 548                    }
 0549                    continueCarrousel = model.automaticTransition;
 550                }
 551            }
 552
 0553            startInmediately = false;
 0554            numberOfInitialJumps = 1;
 555        }
 117556    }
 557
 558    internal IEnumerator RunRightAnimation(int numberOfJumps = 1)
 559    {
 3560        if (currentItemIndex == instantiatedItems.Count - 1)
 561        {
 0562            currentItemIndex = 0;
 0563            yield return RunAnimationCoroutine(CarouselDirection.Left, instantiatedItems.Count - 1);
 564        }
 565        else
 566        {
 3567            currentItemIndex += numberOfJumps;
 3568            yield return RunAnimationCoroutine(CarouselDirection.Right, numberOfJumps);
 569        }
 0570    }
 571
 572    internal IEnumerator RunLeftAnimation(int numberOfJumps = 1)
 573    {
 2574        if (currentItemIndex == 0)
 575        {
 2576            currentItemIndex = instantiatedItems.Count - 1;
 2577            yield return RunAnimationCoroutine(CarouselDirection.Right, instantiatedItems.Count - 1);
 578        }
 579        else
 580        {
 0581            currentItemIndex -= numberOfJumps;
 0582            yield return RunAnimationCoroutine(CarouselDirection.Left, numberOfJumps);
 583        }
 0584    }
 585
 586    internal IEnumerator RunAnimationCoroutine(CarouselDirection direction, int numberOfJumps = 1)
 587    {
 5588        isInTransition = true;
 5589        float currentAnimationTime = 0f;
 5590        float initialNormalizedPos = itemsScroll.horizontalNormalizedPosition;
 591
 5592        if (direction == CarouselDirection.Right)
 5593            currentFinalNormalizedPos = initialNormalizedPos + ((float)numberOfJumps / (instantiatedItems.Count - 1));
 594        else
 0595            currentFinalNormalizedPos = initialNormalizedPos - ((float)numberOfJumps / (instantiatedItems.Count - 1));
 596
 5597        while (currentAnimationTime <= model.animationTransitionTime)
 598        {
 5599            itemsScroll.horizontalNormalizedPosition = Mathf.Clamp01(Mathf.Lerp(
 600                initialNormalizedPos,
 601                currentFinalNormalizedPos,
 602                model.animationCurve.Evaluate(currentAnimationTime / model.animationTransitionTime)));
 603
 5604            currentAnimationTime += Time.deltaTime;
 605
 5606            yield return null;
 607        }
 608
 0609        itemsScroll.horizontalNormalizedPosition = currentFinalNormalizedPos;
 0610        isInTransition = false;
 0611    }
 612
 613    public void GenerateDotsSelector()
 614    {
 38615        List<GameObject> dotsToRemove = new List<GameObject>();
 226616        foreach (Transform child in dotsSelector.transform)
 617        {
 75618            if (child.gameObject == dotButtonTemplate.gameObject)
 619                continue;
 620
 37621            dotsToRemove.Add(child.gameObject);
 622        }
 623
 150624        foreach (GameObject dotToRemove in dotsToRemove)
 625        {
 37626            Utils.SafeDestroy(dotToRemove);
 627        }
 628
 152629        for (int i = 0; i < itemsContainer.childCount; i++)
 630        {
 38631            Button newDotButton = Instantiate(dotButtonTemplate, dotsSelector.transform);
 38632            newDotButton.gameObject.SetActive(true);
 38633            newDotButton.onClick.AddListener(() =>
 634            {
 0635                int dotButtonIndex = newDotButton.transform.GetSiblingIndex() - 1;
 0636                if (dotButtonIndex != currentDotIndex)
 637                {
 0638                    MakeJumpFromDotsSelector(
 639                        Mathf.Abs(dotButtonIndex - currentDotIndex),
 640                        dotButtonIndex > currentDotIndex ? CarouselDirection.Right : CarouselDirection.Left);
 641                }
 0642            });
 643        }
 644
 38645        SetSelectedDot(0);
 38646    }
 647
 648    internal void SetSelectedDot(int index)
 649    {
 167650        int currentIndex = 0;
 167651        currentDotIndex = -1;
 1282652        foreach (Transform child in dotsSelector.transform)
 653        {
 474654            if (child.gameObject == dotButtonTemplate.gameObject)
 655                continue;
 656
 307657            if (currentIndex == index)
 658            {
 144659                child.GetComponent<Image>().color = dotSelectedColor;
 144660                child.transform.localScale = Vector3.one * 1.5f;
 144661                currentDotIndex = index;
 662            }
 663            else
 664            {
 163665                child.GetComponent<Image>().color = dotUnselectedColor;
 163666                child.transform.localScale = Vector3.one;
 667            }
 668
 307669            currentIndex++;
 670        }
 167671    }
 672
 673    public void CleanInstantiatedItems()
 674    {
 0675        instantiatedItems = new List<BaseComponentView>();
 0676    }
 677
 678    public void ResetManualCarousel()
 679    {
 0680        isInTransition = false;
 0681        currentItemIndex = 0;
 0682        SetSelectedDot(0);
 0683    }
 684
 685    internal IEnumerator RegisterCurrentInstantiatedItems()
 686    {
 142687        instantiatedItems.Clear();
 688
 756689        foreach (Transform child in itemsContainer)
 690        {
 236691            BaseComponentView existingItem = child.GetComponent<BaseComponentView>();
 236692            if (existingItem != null)
 236693                instantiatedItems.Add(existingItem);
 694            else
 0695                Destroy(child.gameObject);
 696        }
 697
 698        // In the first loading, before calculating the size of the current items, it is needed to wait for a frame in o
 699        // allow time for the carousel viewport to get its final size to be able to execute the 'ResizeAllItems' functio
 142700        yield return null;
 701
 17702        ResizeAllItems();
 17703        SetManualControlsActive(model.showManualControls);
 17704        GenerateDotsSelector();
 17705    }
 706}