FadeUI.cs 770 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. [RequireComponent(typeof(RawImage))]
  5. [RequireComponent(typeof(Mask))]
  6. public class FadeUI : MonoBehaviour, IFade
  7. {
  8. public float Range
  9. {
  10. get
  11. {
  12. return this.cutoutRange;
  13. }
  14. set
  15. {
  16. this.cutoutRange = value;
  17. this.UpdateMaskCutout(this.cutoutRange);
  18. }
  19. }
  20. private void UpdateMaskCutout(float range)
  21. {
  22. this.mat.SetFloat("_Range", range);
  23. Graphics.Blit(this.texture, this.rt, this.mat);
  24. Mask component = base.GetComponent<Mask>();
  25. component.enabled = false;
  26. component.enabled = true;
  27. }
  28. [SerializeField]
  29. [Range(0f, 1f)]
  30. private float cutoutRange;
  31. [SerializeField]
  32. private Material mat;
  33. [SerializeField]
  34. private RenderTexture rt;
  35. [SerializeField]
  36. private Texture texture;
  37. }