From c83d09260deeee163ce6e8c79aef26f97710ea12 Mon Sep 17 00:00:00 2001 From: Benoit <149511461+BenoitLynx@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:37:30 +0200 Subject: [PATCH 1/2] [BUGFIX] Interfaces - Fix inverted Press & Unpress callback on buttons --- Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs | 2 +- Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs | 6 +++--- Packages/Core/Interfaces/Scripts/LynxTimerButton.cs | 6 +++--- Packages/Core/Interfaces/Scripts/LynxToggleButton.cs | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs b/Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs index ceec49b..6d7884a 100644 --- a/Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs +++ b/Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs @@ -221,7 +221,7 @@ private void ResetInteractable(bool boolean) /// /// CallbackStopRunning is called when a button animation coroutine is complete. /// - /// True to call OnUnpress, false to call OnPress. + /// True to call OnPress, false to call OnUnpress. private void CallbackStopRunning(bool state) { m_isRunning = false; diff --git a/Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs b/Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs index ce845dc..f7a01e1 100644 --- a/Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs +++ b/Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs @@ -249,18 +249,18 @@ private void ResetInteractable(bool boolean) /// /// CallbackStopRunning is called when a button animation coroutine is complete. /// - /// True to call OnUnpress, false to call OnPress. + /// True to call OnPress, false to call OnUnpress. private void CallbackStopRunning(bool state) { m_isRunning = false; if (state) { - OnUnpress.Invoke(); + OnPress.Invoke(); } else { - OnPress.Invoke(); + OnUnpress.Invoke(); } } diff --git a/Packages/Core/Interfaces/Scripts/LynxTimerButton.cs b/Packages/Core/Interfaces/Scripts/LynxTimerButton.cs index e9531c5..997b0c6 100644 --- a/Packages/Core/Interfaces/Scripts/LynxTimerButton.cs +++ b/Packages/Core/Interfaces/Scripts/LynxTimerButton.cs @@ -233,18 +233,18 @@ private void ResetInteractable(bool boolean) /// /// CallbackStopRunning is called when a button animation coroutine is complete. /// - /// True to call OnUnpress, false to call OnPress. + /// True to call OnPress, false to call OnUnpress. private void CallbackStopRunning(bool state) { m_isRunning = false; if (state) { - OnUnpress.Invoke(); + OnPress.Invoke(); } else { - OnPress.Invoke(); + OnUnpress.Invoke(); } } diff --git a/Packages/Core/Interfaces/Scripts/LynxToggleButton.cs b/Packages/Core/Interfaces/Scripts/LynxToggleButton.cs index fea1edc..8a9bf67 100644 --- a/Packages/Core/Interfaces/Scripts/LynxToggleButton.cs +++ b/Packages/Core/Interfaces/Scripts/LynxToggleButton.cs @@ -235,18 +235,18 @@ private void ResetInteractable(bool boolean) /// /// CallbackStopRunning is called when a button animation coroutine is complete. /// - /// True to call OnUnpress, false to call OnPress. + /// True to call OnPress, false to call OnUnpress. private void CallbackStopRunning(bool state) { m_isRunning = false; if (state) { - OnUnpress.Invoke(); + OnPress.Invoke(); } else { - OnPress.Invoke(); + OnUnpress.Invoke(); } } From 34fdbe56201b37c10d2e8a3a1bbdf22cb444c176 Mon Sep 17 00:00:00 2001 From: Benoit <149511461+BenoitLynx@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:31:12 +0200 Subject: [PATCH 2/2] [BUGFIX] Interfaces - Prevent OnUnpress event to be called while moving in scrollview --- .../Interfaces/Scripts/LynxSimpleButton.cs | 28 ++++++++++++++++- .../Interfaces/Scripts/LynxSwitchButton.cs | 31 +++++++++++++++++-- .../Interfaces/Scripts/LynxTimerButton.cs | 28 ++++++++++++++++- .../Interfaces/Scripts/LynxToggleButton.cs | 28 ++++++++++++++++- 4 files changed, 110 insertions(+), 5 deletions(-) diff --git a/Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs b/Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs index 6d7884a..5f0a80f 100644 --- a/Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs +++ b/Packages/Core/Interfaces/Scripts/LynxSimpleButton.cs @@ -14,7 +14,7 @@ namespace Lynx.UI { - public class LynxSimpleButton : Button + public class LynxSimpleButton : Button, IPointerUpHandler, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler, IInitializePotentialDragHandler { #region INSPECTOR VARIABLES @@ -38,6 +38,8 @@ public class LynxSimpleButton : Button private bool m_isCurrentlyPressed = false; // Status of the current object. private bool m_isInteractable = true; // Starting interactable status. + private ScrollRect scrollRect = null; + #endregion #region UNITY API @@ -193,6 +195,30 @@ protected override void DoStateTransition(SelectionState state, bool instant) } } + public void OnInitializePotentialDrag(PointerEventData eventData) + { + if (scrollRect == null) + scrollRect = this.gameObject.GetComponentInParent(); + } + + public void OnBeginDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnBeginDrag(eventData); + } + + public void OnDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnDrag(eventData); + } + + public void OnEndDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnEndDrag(eventData); + } + #endregion #region PRIVATE METHODS diff --git a/Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs b/Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs index f7a01e1..4a44849 100644 --- a/Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs +++ b/Packages/Core/Interfaces/Scripts/LynxSwitchButton.cs @@ -14,7 +14,7 @@ namespace Lynx.UI { - public class LynxSwitchButton : Button + public class LynxSwitchButton : Button, IPointerUpHandler, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler, IInitializePotentialDragHandler { #region INSPECTOR VARIABLES @@ -48,6 +48,8 @@ public class LynxSwitchButton : Button private Vector3 offHandlePosition; private Vector3 onHandlePosition; + private ScrollRect scrollRect = null; + #endregion #region UNITY API @@ -220,7 +222,31 @@ protected override void DoStateTransition(SelectionState state, bool instant) m_secondaryTargetGraphic[i].CrossFadeColor(tintColor, instant ? 0f : colors.fadeDuration, true, true); } } - + + public void OnInitializePotentialDrag(PointerEventData eventData) + { + if(scrollRect == null) + scrollRect = this.gameObject.GetComponentInParent(); + } + + public void OnBeginDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnBeginDrag(eventData); + } + + public void OnDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnDrag(eventData); + } + + public void OnEndDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnEndDrag(eventData); + } + #endregion #region PRIVATE METHODS @@ -385,6 +411,7 @@ public bool IsUsingTheme() return m_useTheme; } + #endregion } } \ No newline at end of file diff --git a/Packages/Core/Interfaces/Scripts/LynxTimerButton.cs b/Packages/Core/Interfaces/Scripts/LynxTimerButton.cs index 997b0c6..53efce7 100644 --- a/Packages/Core/Interfaces/Scripts/LynxTimerButton.cs +++ b/Packages/Core/Interfaces/Scripts/LynxTimerButton.cs @@ -14,7 +14,7 @@ namespace Lynx.UI { - public class LynxTimerButton : Button + public class LynxTimerButton : Button, IPointerUpHandler, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler, IInitializePotentialDragHandler { #region INSPECTOR VARIABLES @@ -46,6 +46,8 @@ public class LynxTimerButton : Button private IEnumerator timerCoroutine = null; // Timer coroutine reference. + private ScrollRect scrollRect = null; + #endregion #region UNITY API @@ -205,6 +207,30 @@ protected override void DoStateTransition(SelectionState state, bool instant) } } + public void OnInitializePotentialDrag(PointerEventData eventData) + { + if (scrollRect == null) + scrollRect = this.gameObject.GetComponentInParent(); + } + + public void OnBeginDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnBeginDrag(eventData); + } + + public void OnDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnDrag(eventData); + } + + public void OnEndDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnEndDrag(eventData); + } + #endregion #region PRIVATE METHODS diff --git a/Packages/Core/Interfaces/Scripts/LynxToggleButton.cs b/Packages/Core/Interfaces/Scripts/LynxToggleButton.cs index 8a9bf67..d527caa 100644 --- a/Packages/Core/Interfaces/Scripts/LynxToggleButton.cs +++ b/Packages/Core/Interfaces/Scripts/LynxToggleButton.cs @@ -14,7 +14,7 @@ namespace Lynx.UI { - public class LynxToggleButton : Button + public class LynxToggleButton : Button, IPointerUpHandler, IPointerDownHandler, IDragHandler, IBeginDragHandler, IEndDragHandler, IInitializePotentialDragHandler { #region INSPECTOR VARIABLES @@ -41,6 +41,8 @@ public class LynxToggleButton : Button private bool m_isToggled = false; // Status of the button. private bool m_isInteractable = true; // Starting interactable status. + private ScrollRect scrollRect = null; + #endregion #region UNITY API @@ -207,6 +209,30 @@ protected override void DoStateTransition(SelectionState state, bool instant) } } + public void OnInitializePotentialDrag(PointerEventData eventData) + { + if (scrollRect == null) + scrollRect = this.gameObject.GetComponentInParent(); + } + + public void OnBeginDrag(PointerEventData eventData) + { + if(scrollRect != null) + scrollRect.OnBeginDrag(eventData); + } + + public void OnDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnDrag(eventData); + } + + public void OnEndDrag(PointerEventData eventData) + { + if (scrollRect != null) + scrollRect.OnEndDrag(eventData); + } + #endregion #region PRIVATE METHODS