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/CrossFader.cs |
+init
Diffstat (limited to 'Client/Assembly-CSharp/CrossFader.cs')
-rw-r--r-- | Client/Assembly-CSharp/CrossFader.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/CrossFader.cs b/Client/Assembly-CSharp/CrossFader.cs new file mode 100644 index 0000000..39ccf82 --- /dev/null +++ b/Client/Assembly-CSharp/CrossFader.cs @@ -0,0 +1,74 @@ +using System; +using UnityEngine; + +public class CrossFader : ISoundPlayer +{ + public string Name { get; set; } + + public AudioSource Player { get; set; } + + public float MaxVolume = 1f; + + public AudioClip target; + + public float Duration = 1.5f; + + private float timer; + + private bool didSwitch; + + public void Update(float dt) + { + if (this.timer < this.Duration) + { + this.timer += dt; + float num = this.timer / this.Duration; + if (num < 0.5f) + { + this.Player.volume = (1f - num * 2f) * this.MaxVolume; + return; + } + if (!this.didSwitch) + { + this.didSwitch = true; + this.Player.Stop(); + this.Player.clip = this.target; + if (this.target) + { + this.Player.Play(); + } + } + this.Player.volume = (num - 0.5f) * 2f * this.MaxVolume; + } + } + + public void SetTarget(AudioClip clip) + { + if (!this.Player.clip) + { + this.didSwitch = false; + this.Player.volume = 0f; + this.timer = 0.5f; + } + else + { + if (this.Player.clip == clip) + { + return; + } + if (this.didSwitch) + { + this.didSwitch = false; + if (this.timer >= this.Duration) + { + this.timer = 0f; + } + else + { + this.timer = this.Duration - this.timer; + } + } + } + this.target = clip; + } +} |