You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/StompyRobot/SRF/Scripts/UI/Unselectable.cs

36 lines
899 B
C#

namespace SRF.UI
{
using Internal;
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// Do not allow an object to become select (automatically unfocus when receiving selection callback)
/// </summary>
[AddComponentMenu(ComponentMenuPaths.Unselectable)]
public sealed class Unselectable : SRMonoBehaviour, ISelectHandler
{
private bool _suspectedSelected;
public void OnSelect(BaseEventData eventData)
{
_suspectedSelected = true;
}
private void Update()
{
if (!_suspectedSelected)
{
return;
}
if (EventSystem.current.currentSelectedGameObject == CachedGameObject)
{
EventSystem.current.SetSelectedGameObject(null);
}
_suspectedSelected = false;
}
}
}