123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- public class FadeImage : Graphic, IFade
- {
- public float Range
- {
- get
- {
- return this.cutoutRange;
- }
- set
- {
- this.cutoutRange = value;
- this.UpdateMaskCutout(this.cutoutRange);
- }
- }
- protected override void Start()
- {
- base.Start();
- this.UpdateMaskTexture(this.maskTexture);
- }
- private void UpdateMaskCutout(float range)
- {
- base.enabled = true;
- this.material.SetFloat("_Range", 1f - range);
- if (range <= 0f)
- {
- base.enabled = false;
- }
- }
- public void UpdateMaskTexture(Texture texture)
- {
- this.material.SetTexture("_MaskTex", texture);
- this.material.SetColor("_Color", this.color);
- }
- [SerializeField]
- private Texture maskTexture;
- [SerializeField]
- [Range(0f, 1f)]
- private float cutoutRange;
- }
|