Rearranging VA call order to first create dependent data and connect it later

parent 73e836a9
......@@ -33,6 +33,7 @@ public class VAUAdapter : MonoBehaviour
if (_VA == null)
{
_VA = new VANet();
Init (); // Try to connect as early as possible
}
return _VA;
}
......@@ -73,8 +74,8 @@ public class VAUAdapter : MonoBehaviour
}
}
// Use this for initialization
void Start()
// Use this for initialization
void OnEnable()
{
if (_VA == null)
_VA = new VANet();
......@@ -83,10 +84,7 @@ public class VAUAdapter : MonoBehaviour
if (DeactivateUnitySoundOnAwake)
DeactivateUnitySound();
}
void OnEnable()
{
if (GetComponent<VAUAuralizationMode>() != null)
GetComponent<VAUAuralizationMode>().AuraStringChanged += OnGlobalAuralizationModeChanged;
}
......
......@@ -12,18 +12,16 @@ public class VAUSignalSourceAudioFile : VAUSignalSource
[Tooltip("Will immediately start the signal source payback.")]
public bool PlayOnStart = true;
void Awake()
{
if (!VAUAdapter.VA.IsConnected())
return;
void OnEnable()
{
_ID = VAUAdapter.VA.CreateSignalSourceBufferFromFile (FilePath, Name);
Debug.Assert (_ID.Length > 0, "Could not create audio file signal source '" + Name + "' from file path " + FilePath);
_ID = VAUAdapter.VA.CreateSignalSourceBufferFromFile(FilePath, Name);
Debug.Assert(_ID.Length > 0, "Could not create audio file signal source '" + Name + "' file from path " + FilePath);
}
void Start()
{
VAUAdapter.VA.SetSignalSourceBufferLooping(_ID, IsLooping);
VAUAdapter.VA.SetSignalSourceBufferLooping (_ID, IsLooping);
}
void Start()
{
if (PlayOnStart)
VAUAdapter.VA.SetSignalSourceBufferPlaybackAction(_ID, "PLAY");
}
......
......@@ -47,7 +47,7 @@ public class VAUSoundReceiver : MonoBehaviour {
GetComponent<VAUAuralizationMode>().AuraStringChanged += OnSoundReceiverAuralizationModeChanged;
}
void Update ()
void Update()
{
SetSoundReceiverPositionOrientation();
}
......
......@@ -12,10 +12,10 @@ public class VAUSoundSource : MonoBehaviour
public bool stopOnDisable = false;
[Tooltip("Insert a custom VAUDirectivity-Script.")]
public VAUDirectivity Directivity;
public VAUDirectivity Directivity = null;
[Tooltip("Insert a custom VAUSignalSource-Script.")]
public VAUSignalSource SignalSource;
public VAUSignalSource SignalSource = null;
private VANet _VA = null;
......@@ -23,7 +23,6 @@ public class VAUSoundSource : MonoBehaviour
private Quaternion q;
private Transform t;
private string _AudiofileSignalSource = null;
private bool enable = false;
public int ID
{
......@@ -33,17 +32,20 @@ public class VAUSoundSource : MonoBehaviour
}
}
void Start()
{
_VA = VAUAdapter.VA;
void OnEnable()
{
_VA = VAUAdapter.VA;
if (!_VA.IsConnected())
return;
if (!_VA.IsConnected())
return;
// Add sound source
_ID = _VA.CreateSoundSource(this.name);
_VA.SetSoundSourceAuralizationMode(_ID, "all");
// Add sound source
_ID = _VA.CreateSoundSource(this.name);
_VA.SetSoundSourceAuralizationMode(_ID, "all");
}
void Start()
{
// Connect to directivity, if linked or attached
if (Directivity)
_VA.SetSoundSourceDirectivity(_ID, Directivity.ID);
......@@ -51,9 +53,11 @@ public class VAUSoundSource : MonoBehaviour
_VA.SetSoundSourceDirectivity(_ID, GetComponent<VAUDirectivity>().ID);
// Connect to signal source, if linked or attached
if (SignalSource)
_VA.SetSoundSourceSignalSource(_ID, SignalSource.ID);
else if (GetComponent<AudioSource>())
if (SignalSource)
{
_VA.SetSoundSourceSignalSource (_ID, SignalSource.ID);
}
else if (GetComponent<AudioSource>())
{
// Set gain control once
_VA.SetSoundSourceMuted(_ID, GetComponent<AudioSource>().mute);
......@@ -75,7 +79,6 @@ public class VAUSoundSource : MonoBehaviour
_VA.SetSoundSourceSignalSource(_ID, _AudiofileSignalSource);
}
enable = true;
}
// Activate auralization mode, if available
......@@ -117,12 +120,6 @@ public class VAUSoundSource : MonoBehaviour
_VA.SetSoundSourceAuralizationMode(_ID, AuraMode);
}
public void OnEnable()
{
if (enable)
_VA.SetSignalSourceBufferPlaybackAction(_AudiofileSignalSource, "play");
}
public void OnDisable()
{
if (GetComponent<VAUAuralizationMode>())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment