AudioMixerProperties.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using UnityEngine.Audio;
  3. using UnityEngine.Playables;
  4. namespace UnityEngine.Timeline
  5. {
  6. [Serializable]
  7. class AudioMixerProperties : PlayableBehaviour
  8. {
  9. [Range(0.0f, 1.0f)]
  10. public float volume = 1.0f;
  11. [Range(-1.0f, 1.0f)]
  12. public float stereoPan = 0.0f;
  13. [Range(0.0f, 1.0f)]
  14. public float spatialBlend = 0.0f;
  15. public override void PrepareFrame(Playable playable, FrameData info)
  16. {
  17. if (!playable.IsValid() || !playable.IsPlayableOfType<AudioMixerPlayable>())
  18. return;
  19. var inputCount = playable.GetInputCount();
  20. for (int i = 0; i < inputCount; ++i)
  21. {
  22. if (playable.GetInputWeight(i) > 0.0f)
  23. {
  24. var input = playable.GetInput(i);
  25. if (input.IsValid() && input.IsPlayableOfType<AudioClipPlayable>())
  26. {
  27. var audioClipPlayable = (AudioClipPlayable)input;
  28. var audioClipProperties = input.GetHandle().GetObject<AudioClipProperties>();
  29. audioClipPlayable.SetVolume(Mathf.Clamp01(volume * audioClipProperties.volume));
  30. audioClipPlayable.SetStereoPan(Mathf.Clamp(stereoPan, -1.0f, 1.0f));
  31. audioClipPlayable.SetSpatialBlend(Mathf.Clamp01(spatialBlend));
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }