FadeImage.cs 797 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. public class FadeImage : Graphic, IFade
  5. {
  6. public float Range
  7. {
  8. get
  9. {
  10. return this.cutoutRange;
  11. }
  12. set
  13. {
  14. this.cutoutRange = value;
  15. this.UpdateMaskCutout(this.cutoutRange);
  16. }
  17. }
  18. protected override void Start()
  19. {
  20. base.Start();
  21. this.UpdateMaskTexture(this.maskTexture);
  22. }
  23. private void UpdateMaskCutout(float range)
  24. {
  25. base.enabled = true;
  26. this.material.SetFloat("_Range", 1f - range);
  27. if (range <= 0f)
  28. {
  29. base.enabled = false;
  30. }
  31. }
  32. public void UpdateMaskTexture(Texture texture)
  33. {
  34. this.material.SetTexture("_MaskTex", texture);
  35. this.material.SetColor("_Color", this.color);
  36. }
  37. [SerializeField]
  38. private Texture maskTexture;
  39. [SerializeField]
  40. [Range(0f, 1f)]
  41. private float cutoutRange;
  42. }