FlashGraphic.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5. namespace SRF.UI
  6. {
  7. [AddComponentMenu("SRF/UI/Flash Graphic")]
  8. [ExecuteInEditMode]
  9. public class FlashGraphic : UIBehaviour, IEventSystemHandler, IPointerDownHandler, IPointerUpHandler
  10. {
  11. public void OnPointerDown(PointerEventData eventData)
  12. {
  13. this.Target.CrossFadeColor(this.FlashColor, 0f, true, true);
  14. }
  15. public void OnPointerUp(PointerEventData eventData)
  16. {
  17. this.Target.CrossFadeColor(this.DefaultColor, this.DecayTime, true, true);
  18. }
  19. protected override void OnEnable()
  20. {
  21. base.OnEnable();
  22. this.Target.CrossFadeColor(this.DefaultColor, 0f, true, true);
  23. }
  24. protected void Update()
  25. {
  26. }
  27. public void Flash()
  28. {
  29. this.Target.CrossFadeColor(this.FlashColor, 0f, true, true);
  30. this.Target.CrossFadeColor(this.DefaultColor, this.DecayTime, true, true);
  31. }
  32. public float DecayTime = 0.15f;
  33. public Color DefaultColor = new Color(1f, 1f, 1f, 0f);
  34. public Color FlashColor = Color.white;
  35. public Graphic Target;
  36. }
  37. }