blob: 39ccf82c001d65dfb1e5ea4b752c9033e9b07ef2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
}
}
|