From 8fc9e8aba51952f194e1f7f51126c6e4986379c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Fejzagi=C4=87?= Date: Wed, 1 Mar 2023 11:32:14 +0100 Subject: [PATCH] Update ResetSelectableHighlight.cs --- .../Utilities/ResetSelectableHighlight.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Runtime/Scripts/Utilities/ResetSelectableHighlight.cs b/Runtime/Scripts/Utilities/ResetSelectableHighlight.cs index 19b9590..5f4c647 100644 --- a/Runtime/Scripts/Utilities/ResetSelectableHighlight.cs +++ b/Runtime/Scripts/Utilities/ResetSelectableHighlight.cs @@ -1,29 +1,24 @@ /// Credit SimonDarksideJ +using UnityEngine.EventSystems; + namespace UnityEngine.UI.Extensions { - /* - Handy Selectable script to un-highlight a selectable component in Unity (e.g. a Button) when the user moves away from it, EVEN IF the user has holding a button on it. - - Resolves the situation where Unity UI Components remain in a highlighted state even after the pointer has moved away (e.g. user holding a button, mouse, pointer down). - Now whenever the cursor leaves the component, it will force the UI component to revert to un-highlighted. - */ - - using UnityEngine; - using UnityEngine.EventSystems; - using UnityEngine.UI; - + /// + /// Handy Selectable script to un-highlight a selectable component in Unity (e.g. a Button) when the user moves away from it, EVEN IF the user has holding a button on it. + /// Resolves the situation where Unity UI Components remain in a highlighted state even after the pointer has moved away (e.g. user holding a button, mouse, pointer down). + /// Now whenever the cursor leaves the component, it will force the UI component to revert to un-highlighted. + /// [AddComponentMenu("UI/Extensions/ResetSelectableHighlight", 31)] [RequireComponent(typeof(Selectable))] public class ResetSelectableHighlight : MonoBehaviour, IPointerExitHandler { [SerializeField] - private Selectable attachedSelectable; + private Selectable attachedSelectable = null; - // Start is called before the first frame update - void Awake() + private void Awake() { - if (!attachedSelectable) + if (attachedSelectable == null || !attachedSelectable) { attachedSelectable = GetComponent(); } @@ -31,7 +26,12 @@ namespace UnityEngine.UI.Extensions public void OnPointerExit(PointerEventData eventData) { + if (!attachedSelectable.interactable) + { + return; + } + attachedSelectable.targetGraphic.CrossFadeColor(attachedSelectable.colors.normalColor, 0f, true, true); } } -} \ No newline at end of file +}