AudioMixerProperties.cs
1.44 KB
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
using System;
using UnityEngine.Audio;
using UnityEngine.Playables;
namespace UnityEngine.Timeline
{
[Serializable]
class AudioMixerProperties : PlayableBehaviour
{
[Range(0.0f, 1.0f)]
public float volume = 1.0f;
[Range(-1.0f, 1.0f)]
public float stereoPan = 0.0f;
[Range(0.0f, 1.0f)]
public float spatialBlend = 0.0f;
public override void PrepareFrame(Playable playable, FrameData info)
{
if (!playable.IsValid() || !playable.IsPlayableOfType<AudioMixerPlayable>())
return;
var inputCount = playable.GetInputCount();
for (int i = 0; i < inputCount; ++i)
{
if (playable.GetInputWeight(i) > 0.0f)
{
var input = playable.GetInput(i);
if (input.IsValid() && input.IsPlayableOfType<AudioClipPlayable>())
{
var audioClipPlayable = (AudioClipPlayable)input;
var audioClipProperties = input.GetHandle().GetObject<AudioClipProperties>();
audioClipPlayable.SetVolume(Mathf.Clamp01(volume * audioClipProperties.volume));
audioClipPlayable.SetStereoPan(Mathf.Clamp(stereoPan, -1.0f, 1.0f));
audioClipPlayable.SetSpatialBlend(Mathf.Clamp01(spatialBlend));
}
}
}
}
}
}