ErrorNotifier.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using UnityEngine;
  2. namespace SRDebugger.UI.Other
  3. {
  4. public class ErrorNotifier : MonoBehaviour
  5. {
  6. public bool IsVisible
  7. {
  8. get { return _isShowing; }
  9. }
  10. private const float DisplayTime = 6;
  11. [SerializeField]
  12. private Animator _animator = null;
  13. private int _triggerHash;
  14. private float _hideTime;
  15. private bool _isShowing;
  16. private bool _queueWarning;
  17. void Awake()
  18. {
  19. _triggerHash = Animator.StringToHash("Display");
  20. }
  21. public void ShowErrorWarning()
  22. {
  23. _queueWarning = true;
  24. }
  25. void Update()
  26. {
  27. if (_queueWarning)
  28. {
  29. _hideTime = Time.realtimeSinceStartup + DisplayTime;
  30. if (!_isShowing)
  31. {
  32. _isShowing = true;
  33. _animator.SetBool(_triggerHash, true);
  34. }
  35. _queueWarning = false;
  36. }
  37. if (_isShowing && Time.realtimeSinceStartup > _hideTime)
  38. {
  39. _animator.SetBool(_triggerHash, false);
  40. _isShowing = false;
  41. }
  42. }
  43. }
  44. }