Select Git revision
VAUSoundSourceGeneric.cs
-
Carolin Breuer authoredCarolin Breuer authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
VAUSoundSourceGeneric.cs 3.74 KiB
using System;
using UnityEngine;
namespace VAUnity
{
/// <summary>
/// Create a Sound Source in VA based on the inspector settings
/// </summary>
public class VAUSoundSourceGeneric : VAUSoundSource
{
[Tooltip("Insert a custom VAUSignalSource-Script.")]
[SerializeField] private VAUSignalSource signalSource;
[Tooltip("Sound power in Watts (default is 31mW)")]
[Min(0)][SerializeField] private float soundPower = 0.0031f;
[Tooltip("Mutes the sound source")]
[SerializeField] private bool isMuted = false;
[Tooltip("Will immediately start the signal source payback.")]
[SerializeField] protected bool playOnStart = false;
public override bool IsLooping => signalSource.IsLooping;
public override string SignalSourceId => signalSource.ID;
/// <summary>
/// Init Sound Source and Signal Source in VA
/// </summary>
protected override void Start()
{
base.Start();
_va.SetSoundSourceAuralizationMode(_id, "all");
UpdateSoundSource(soundPower, isMuted, true);
// Connect to directivity, if linked or attached
// Connect to signal source, if linked or attached
if (signalSource)
{
_va.SetSoundSourceSignalSource(_id, signalSource.ID);
}
else
{
Debug.LogError("Signal Source not found", this);
}
if(playOnStart)
Play();
}
/// <summary>
/// Get Called every frames and update changes in Sound Power and mute status
/// </summary>
protected override void Update()
{
base.Update();
UpdateSoundSource(soundPower, isMuted);
}
protected override void OnDestroy()
{
base.OnDestroy();
//_VA = VAUnity.VA;
if (_va.IsConnected())
{
// Temptative signal source deletion
if (signalSource.ID != null)
_va.DeleteSignalSource (signalSource.ID);
}
}