From 67c2da49b10ff152fd296617200368bacae31f91 Mon Sep 17 00:00:00 2001 From: Gabriel Juchault Date: Wed, 21 Nov 2018 13:11:30 +0000 Subject: [PATCH 1/4] feat(cooldown-button): add a `StartCooldown` to start cooldown from outside --- Scripts/Controls/CooldownButton.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Scripts/Controls/CooldownButton.cs b/Scripts/Controls/CooldownButton.cs index d1c0e05..56b98f8 100644 --- a/Scripts/Controls/CooldownButton.cs +++ b/Scripts/Controls/CooldownButton.cs @@ -139,6 +139,16 @@ namespace UnityEngine.UI.Extensions } } + /// + /// Start a cooldown from outside + /// + public void StartCooldown() + { + if(OnCooldownStart != null) OnCooldownStart.Invoke(eventData.button); + cooldownTimeRemaining = cooldownTimeout; + cooldownActive = cooldownInEffect = true; + } + /// /// Stop a running Cooldown and reset all values /// From 3737c610b6d0299eede4c4f5a64072c3cb72ead6 Mon Sep 17 00:00:00 2001 From: Gabriel Juchault Date: Wed, 21 Nov 2018 13:14:32 +0000 Subject: [PATCH 2/4] fix(cooldown-button): do not trigger event on StartCooldown as it can be triggered next to `StartCooldown` call --- Scripts/Controls/CooldownButton.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Scripts/Controls/CooldownButton.cs b/Scripts/Controls/CooldownButton.cs index 56b98f8..a346b22 100644 --- a/Scripts/Controls/CooldownButton.cs +++ b/Scripts/Controls/CooldownButton.cs @@ -144,7 +144,6 @@ namespace UnityEngine.UI.Extensions /// public void StartCooldown() { - if(OnCooldownStart != null) OnCooldownStart.Invoke(eventData.button); cooldownTimeRemaining = cooldownTimeout; cooldownActive = cooldownInEffect = true; } From ff548fec7eaf37a152d201d6426c3755bff1e27c Mon Sep 17 00:00:00 2001 From: Gabriel Juchault Date: Wed, 21 Nov 2018 13:41:20 +0000 Subject: [PATCH 3/4] fix(cooldown-button): restore event --- Scripts/Controls/CooldownButton.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Scripts/Controls/CooldownButton.cs b/Scripts/Controls/CooldownButton.cs index a346b22..9d15ecd 100644 --- a/Scripts/Controls/CooldownButton.cs +++ b/Scripts/Controls/CooldownButton.cs @@ -144,6 +144,7 @@ namespace UnityEngine.UI.Extensions /// public void StartCooldown() { + OnCooldownStart.Invoke(new PointerEventData.InputButton()); cooldownTimeRemaining = cooldownTimeout; cooldownActive = cooldownInEffect = true; } From c2b8b39fa15bac7781344fccdb0b7c214e1807dc Mon Sep 17 00:00:00 2001 From: Gabriel Juchault Date: Wed, 21 Nov 2018 14:47:49 +0000 Subject: [PATCH 4/4] fix(cooldown-button): add a fake event to avoid null buttonSource --- Scripts/Controls/CooldownButton.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Scripts/Controls/CooldownButton.cs b/Scripts/Controls/CooldownButton.cs index 9d15ecd..502362b 100644 --- a/Scripts/Controls/CooldownButton.cs +++ b/Scripts/Controls/CooldownButton.cs @@ -144,9 +144,11 @@ namespace UnityEngine.UI.Extensions /// public void StartCooldown() { - OnCooldownStart.Invoke(new PointerEventData.InputButton()); + PointerEventData emptySource = new PointerEventData(EventSystem.current); + buttonSource = emptySource; + OnCooldownStart.Invoke(emptySource.button); cooldownTimeRemaining = cooldownTimeout; - cooldownActive = cooldownInEffect = true; + CooldownActive = cooldownInEffect = true; } ///