UGuiRule.cs 1017 B

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