diff options
author | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
commit | e9ea621b93fbb58d9edfca8375918791637bbd52 (patch) | |
tree | 19ce3b1c1f2d51eda6878c9d0f2c9edc27f13650 /Client/Assembly-CSharp/AlphaPulse.cs |
+init
Diffstat (limited to 'Client/Assembly-CSharp/AlphaPulse.cs')
-rw-r--r-- | Client/Assembly-CSharp/AlphaPulse.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/AlphaPulse.cs b/Client/Assembly-CSharp/AlphaPulse.cs new file mode 100644 index 0000000..e28579e --- /dev/null +++ b/Client/Assembly-CSharp/AlphaPulse.cs @@ -0,0 +1,43 @@ +using System; +using UnityEngine; + +public class AlphaPulse : MonoBehaviour +{ + public float Offset = 1f; + + public float Duration = 2.5f; + + private SpriteRenderer rend; + + private MeshRenderer mesh; + + public FloatRange AlphaRange = new FloatRange(0.2f, 0.5f); + + public Color baseColor = Color.white; + + public void SetColor(Color c) + { + this.Start(); + this.baseColor = c; + this.Update(); + } + + private void Start() + { + this.mesh = base.GetComponent<MeshRenderer>(); + this.rend = base.GetComponent<SpriteRenderer>(); + } + + public void Update() + { + float v = Mathf.Abs(Mathf.Cos((this.Offset + Time.time) * 3.1415927f / this.Duration)); + if (this.rend) + { + this.rend.color = new Color(this.baseColor.r, this.baseColor.g, this.baseColor.b, this.AlphaRange.Lerp(v)); + } + if (this.mesh) + { + this.mesh.material.SetColor("_Color", new Color(this.baseColor.r, this.baseColor.g, this.baseColor.b, this.AlphaRange.Lerp(v))); + } + } +} |