30 lines
866 B
C#
30 lines
866 B
C#
// Copyright (c) Pixel Crushers. All rights reserved.
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace PixelCrushers
|
|
{
|
|
|
|
/// <summary>
|
|
/// This script deselects the previous selectable when the pointer enters this one.
|
|
/// </summary>
|
|
[AddComponentMenu("")] // Use wrapper.
|
|
[RequireComponent(typeof(Selectable))]
|
|
public class DeselectPreviousOnPointerEnter : MonoBehaviour, IPointerEnterHandler, IDeselectHandler
|
|
{
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (!EventSystem.current.alreadySelecting)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(this.gameObject);
|
|
}
|
|
}
|
|
|
|
public void OnDeselect(BaseEventData eventData)
|
|
{
|
|
GetComponent<Selectable>().OnPointerExit(null);
|
|
}
|
|
}
|
|
} |