From 263368ba8d2b561a4f9e2de8ca00b775737c70e6 Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Mon, 28 Sep 2020 18:12:35 +0100 Subject: [PATCH] Fixed public GoToScreen call to only raise events internally (not multiple) --- Runtime/Scripts/Layout/HorizontalScrollSnap.cs | 2 +- Runtime/Scripts/Layout/ScrollSnapBase.cs | 6 +++--- Runtime/Scripts/Layout/VerticalScrollSnap.cs | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs index 1baacfd..a441183 100644 --- a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs @@ -238,7 +238,7 @@ namespace UnityEngine.UI.Extensions if (JumpOnEnable || !RestartOnEnable) SetScrollContainerPosition(); if (RestartOnEnable) - GoToScreen(StartingScreen); + GoToScreen(StartingScreen, true); } /// diff --git a/Runtime/Scripts/Layout/ScrollSnapBase.cs b/Runtime/Scripts/Layout/ScrollSnapBase.cs index b8b3087..893ba29 100644 --- a/Runtime/Scripts/Layout/ScrollSnapBase.cs +++ b/Runtime/Scripts/Layout/ScrollSnapBase.cs @@ -357,7 +357,7 @@ namespace UnityEngine.UI.Extensions /// *Note, this is based on a 0 starting index - 0 to x /// /// 0 starting index of page to jump to - public void GoToScreen(int screenIndex) + public void GoToScreen(int screenIndex, bool local = false) { if (screenIndex <= _screens - 1 && screenIndex >= 0) { @@ -366,7 +366,7 @@ namespace UnityEngine.UI.Extensions _lerp = true; CurrentPage = screenIndex; GetPositionforPage(_currentPage, ref _lerp_target); - ScreenChange(); + if(local) ScreenChange(); } } @@ -623,7 +623,7 @@ namespace UnityEngine.UI.Extensions /// public void ChangePage(int page) { - GoToScreen(page); + GoToScreen(page, true); } public void OnPointerClick(PointerEventData eventData) diff --git a/Runtime/Scripts/Layout/VerticalScrollSnap.cs b/Runtime/Scripts/Layout/VerticalScrollSnap.cs index e0c5bb0..0093daa 100644 --- a/Runtime/Scripts/Layout/VerticalScrollSnap.cs +++ b/Runtime/Scripts/Layout/VerticalScrollSnap.cs @@ -228,10 +228,13 @@ namespace UnityEngine.UI.Extensions { InitialiseChildObjectsFromScene(); DistributePages(); - if (MaskArea) UpdateVisible(); + if (MaskArea) + UpdateVisible(); - if (JumpOnEnable || !RestartOnEnable) SetScrollContainerPosition(); - if(RestartOnEnable) GoToScreen(StartingScreen); + if (JumpOnEnable || !RestartOnEnable) + SetScrollContainerPosition(); + if (RestartOnEnable) + GoToScreen(StartingScreen, true); } ///