Unselectable.cs 899 B

1234567891011121314151617181920212223242526272829303132333435
  1. namespace SRF.UI
  2. {
  3. using Internal;
  4. using UnityEngine;
  5. using UnityEngine.EventSystems;
  6. /// <summary>
  7. /// Do not allow an object to become select (automatically unfocus when receiving selection callback)
  8. /// </summary>
  9. [AddComponentMenu(ComponentMenuPaths.Unselectable)]
  10. public sealed class Unselectable : SRMonoBehaviour, ISelectHandler
  11. {
  12. private bool _suspectedSelected;
  13. public void OnSelect(BaseEventData eventData)
  14. {
  15. _suspectedSelected = true;
  16. }
  17. private void Update()
  18. {
  19. if (!_suspectedSelected)
  20. {
  21. return;
  22. }
  23. if (EventSystem.current.currentSelectedGameObject == CachedGameObject)
  24. {
  25. EventSystem.current.SetSelectedGameObject(null);
  26. }
  27. _suspectedSelected = false;
  28. }
  29. }
  30. }