From d69b378f33a1cb95e7dd8fa77878084eaa702991 Mon Sep 17 00:00:00 2001 From: Harris Bright Date: Tue, 14 Jul 2020 21:47:48 +0100 Subject: [PATCH] Added new public method to PaginationManager, to faciliate adding or removing toggles at runtime. --- Runtime/Scripts/Utilities/PaginationManager.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Runtime/Scripts/Utilities/PaginationManager.cs b/Runtime/Scripts/Utilities/PaginationManager.cs index 79ca909..c80b21f 100644 --- a/Runtime/Scripts/Utilities/PaginationManager.cs +++ b/Runtime/Scripts/Utilities/PaginationManager.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; /// Credit Brogan King (@BroganKing) /// Original Sourced from - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/158/pagination-script @@ -44,7 +44,16 @@ namespace UnityEngine.UI.Extensions scrollSnap.OnSelectionPageChangedEvent.AddListener(SetToggleGraphics); scrollSnap.OnSelectionChangeEndEvent.AddListener(OnPageChangeEnd); - // add selectables to list + ResetPaginationChildren(); + } + + /// + /// Remake the internal list of child toggles (m_PaginationChildren). + /// Used after adding/removing a toggle. + /// + public void ResetPaginationChildren() + { + // add selectables to list m_PaginationChildren = GetComponentsInChildren().ToList(); for (int i = 0; i < m_PaginationChildren.Count; i++) { @@ -61,7 +70,6 @@ namespace UnityEngine.UI.Extensions Debug.LogWarning("Uneven pagination icon to page count"); } - /// /// Calling from other scripts if you need to change screens programmatically /// @@ -128,4 +136,4 @@ namespace UnityEngine.UI.Extensions isAClick = false; } } -} \ No newline at end of file +}