Update ResetSelectableHighlight.cs
parent
d2b10980e3
commit
8fc9e8aba5
|
@ -1,29 +1,24 @@
|
||||||
/// Credit SimonDarksideJ
|
/// Credit SimonDarksideJ
|
||||||
|
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
/*
|
/// <summary>
|
||||||
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.
|
/// 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).
|
||||||
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.
|
||||||
Now whenever the cursor leaves the component, it will force the UI component to revert to un-highlighted.
|
/// </summary>
|
||||||
*/
|
|
||||||
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
[AddComponentMenu("UI/Extensions/ResetSelectableHighlight", 31)]
|
[AddComponentMenu("UI/Extensions/ResetSelectableHighlight", 31)]
|
||||||
[RequireComponent(typeof(Selectable))]
|
[RequireComponent(typeof(Selectable))]
|
||||||
public class ResetSelectableHighlight : MonoBehaviour, IPointerExitHandler
|
public class ResetSelectableHighlight : MonoBehaviour, IPointerExitHandler
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Selectable attachedSelectable;
|
private Selectable attachedSelectable = null;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
private void Awake()
|
||||||
void Awake()
|
|
||||||
{
|
{
|
||||||
if (!attachedSelectable)
|
if (attachedSelectable == null || !attachedSelectable)
|
||||||
{
|
{
|
||||||
attachedSelectable = GetComponent<Selectable>();
|
attachedSelectable = GetComponent<Selectable>();
|
||||||
}
|
}
|
||||||
|
@ -31,7 +26,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
public void OnPointerExit(PointerEventData eventData)
|
public void OnPointerExit(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
|
if (!attachedSelectable.interactable)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
attachedSelectable.targetGraphic.CrossFadeColor(attachedSelectable.colors.normalColor, 0f, true, true);
|
attachedSelectable.targetGraphic.CrossFadeColor(attachedSelectable.colors.normalColor, 0f, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue