diff --git a/VACS.cs b/VACS.cs index ce9d234b50c0bcc8b898019959d5106fb6c5a4e4..ed6d6855d786cfe41310d2c5eaacb67dbc51b803 100644 --- a/VACS.cs +++ b/VACS.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using System.Text; +using UnityEngine; namespace VA { @@ -94,14 +95,13 @@ namespace VA public int LoadHRIRDataset(string FilePath, string Name) { - Console.WriteLine("test"); try { return NativeLoadHRIRDataset(_NetClient, FilePath, Name); } catch { - Console.WriteLine("ErrorError"); + Debug.Log("HRIR-Error-Catch."); } return -1; } diff --git a/VAUAdapter.cs b/VAUAdapter.cs index d326d64f80534cd5e60b7c70b4b53773b4638fde..b38c57bef0a1990cf66c67d3e4e75982b285a606 100644 --- a/VAUAdapter.cs +++ b/VAUAdapter.cs @@ -29,7 +29,6 @@ public class VAUAdapter : MonoBehaviour { if (_VA == null) { _VA = new VANet(); - Debug.Log("Connected to VAServer through VANet-get."); Init(); } @@ -39,18 +38,17 @@ public class VAUAdapter : MonoBehaviour { private static void Init() { - try + if (!_VA.IsConnected()) { _VA.Connect(HostIP, Port); _VA.Reset(); defaulthrir = _VA.LoadHRIRDataset(DefaultHRIRPath, "DefaultHRIR"); defaultdirectivity = _VA.LoadDirectivity(DefaultDirectivityPath, "DefaultDirectivity"); _VA.SetGlobalAuralizationMode(GlobalAuralizationMode); + Debug.Log("Connect to Server: " + HostIP); } - catch(ExternalException e) - { - Debug.Log(e.ToString()); - } + else + Debug.Log("Already connected."); } public static int DefaultHRIR @@ -75,17 +73,14 @@ public class VAUAdapter : MonoBehaviour { { if(_VA==null) _VA = new VANet(); - if (!_VA.IsConnected()) - { - Debug.Log("Connected to VAServer through Adapter."); - Init(); - } + Init(); + DeactivateUnitySound(); } void OnEnable() { - // if (GetComponent<VAUAuralizationMode>() != null) - // VAUAuralizationMode.AuraStringChanged += OnGlobalAuralizationModeChanged; + if (GetComponent<VAUAuralizationMode>() != null) + GetComponent<VAUAuralizationMode>().AuraStringChanged += OnGlobalAuralizationModeChanged; } void OnGlobalAuralizationModeChanged(string AuraMode) @@ -108,8 +103,23 @@ public class VAUAdapter : MonoBehaviour { Debug.Log("Listener " + Listener.ID + " deleted."); _VA.DeleteListener(Listener.ID); } + if (GetComponent<VAUAuralizationMode>() != null) + GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnGlobalAuralizationModeChanged; _VA.Disconnect(); - // if (GetComponent<VAUAuralizationMode>() != null) - // VAUAuralizationMode.AuraStringChanged -= OnGlobalAuralizationModeChanged; + + } + + void DeactivateUnitySound() + { + AudioSource[] audioSources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[]; + foreach (AudioSource audioSource in audioSources) + { + audioSource.enabled = false; + } + AudioListener[] audioListeners = FindObjectsOfType(typeof(AudioListener)) as AudioListener[]; + foreach (AudioListener audioListener in audioListeners) + { + audioListener.enabled = false; + } } } diff --git a/VAUListener.cs b/VAUListener.cs index 706d0f4d0a965f6082268f60aaf50007fb2cc710..a28d3a3bb1506aee8d18535905e37dc1c2378b47 100644 --- a/VAUListener.cs +++ b/VAUListener.cs @@ -6,7 +6,7 @@ using VA; public class VAUListener : MonoBehaviour { - public string listenername = "MyListener"; + public string listenername = "Listener"; private int Listener; private VANet _VA = null; private Quaternion q; @@ -25,15 +25,23 @@ public class VAUListener : MonoBehaviour { { _VA = VAUAdapter.VA; Listener = _VA.CreateListener(listenername, 0, VAUAdapter.DefaultHRIR); + listenername += " " + Listener; _VA.SetListenerAuralizationMode(Listener, "all"); - Debug.Log("Listener " + Listener + " created"); + Debug.Log(listenername + " created"); _VA.SetListenerHRIRDataset(Listener, VAUAdapter.DefaultHRIR); + SetListenerPositionOrientation(); if (GetComponent<VAUAuralizationMode>() != null) GetComponent<VAUAuralizationMode>().AuraStringChanged += OnListenerAuralizationModeChanged; + } // Update is called once per frame void Update () + { + SetListenerPositionOrientation(); + } + + void SetListenerPositionOrientation() { t = GetComponent<Transform>(); q = t.rotation; @@ -41,13 +49,8 @@ public class VAUListener : MonoBehaviour { Vector3 view = q * Vector3.forward; Vector3 view_ogl = new Vector3(view.x, view.y, -view.z); Vector3 up_ogl = new Vector3(up.x, up.y, -up.z); - _VA.SetListenerPosition(Listener, t.transform.position.x, t.transform.position.y, -t.transform.position.z); _VA.SetListenerOrientationVU(Listener, view_ogl.x, view_ogl.y, view_ogl.z, up_ogl.x, up_ogl.y, up_ogl.z); - //Quaternion q_ogl = new Quaternion(q.x, q.y, -q.z, -q.w); - //Vector3 t1 = new Vector3(0, 0, 1); - //Vector3 t1_ogl = ( q_ogl * t1 ); // result: 0 0 -1 - // Debug.Log(t1_ogl); } void OnListenerAuralizationModeChanged(string AuraMode) diff --git a/VAUSoundSource.cs b/VAUSoundSource.cs index 5d69ae04a0b88e39b0ce3e70b6edd2338923fe01..2119222b391978fd14d0645c185110afc8961dd8 100644 --- a/VAUSoundSource.cs +++ b/VAUSoundSource.cs @@ -44,30 +44,38 @@ public class VAUSoundSource : MonoBehaviour { else directivity = _VA.LoadDirectivity(directivitypath, "SoundSource " + SoundSource + " Directivity"); if (GetComponent<AudioSource>() != null) - { - SignalSource = _VA.CreateAudiofileSignalSource( AssetDatabase.GetAssetPath(GetComponent<AudioSource>().clip), this.name + "_signal"); - _VA.SetSoundSourceSignalSource(SoundSource, SignalSource); - Debug.Log(SignalSource + " connected to SoundSource " + SoundSource); - _VA.SetAudiofileSignalSourcePlaybackAction(SignalSource, "PLAYING"); - _VA.SetAudiofileSignalSourceIsLooping(SignalSource, islooping); + { + if (GetComponent<AudioSource>().clip != null) + { + SignalSource = _VA.CreateAudiofileSignalSource(AssetDatabase.GetAssetPath(GetComponent<AudioSource>().clip), this.name + "_signal"); + _VA.SetSoundSourceSignalSource(SoundSource, SignalSource); + Debug.Log(SignalSource + " connected to SoundSource " + SoundSource); + _VA.SetAudiofileSignalSourcePlaybackAction(SignalSource, "PLAYING"); + _VA.SetAudiofileSignalSourceIsLooping(SignalSource, islooping); + } + else + Debug.Log("No Clip on AudioSource of GameObject: " + gameObject.name); } + else + Debug.Log("No AudioSource on GameObject: " + gameObject.name); if (GetComponent<VAUAuralizationMode>() != null) { GetComponent<VAUAuralizationMode>().AuraStringChanged += OnSoundSourceAuralizationModeChanged; } + SetSoundSourcePositionOrientation(); } // Update is called once per frame void Update() { - SetSoundSourcePosition(); + SetSoundSourcePositionOrientation(); SetSoundSourcePlaybackState(); //_VA.SetSoundSourceVolume(SoundSource, Volume); <- flaot ändern } - void SetSoundSourcePosition() + void SetSoundSourcePositionOrientation() { //position and oritentation -> VA t = GetComponent<Transform>(); @@ -81,7 +89,11 @@ public class VAUSoundSource : MonoBehaviour { void SetSoundSourcePlaybackState() { - _VA.SetSoundSourceMuted(SoundSource, GetComponent<AudioSource>().mute); + if (ismuted != GetComponent<AudioSource>().mute) + { + _VA.SetSoundSourceMuted(SoundSource, GetComponent<AudioSource>().mute); + ismuted = GetComponent<AudioSource>().mute; + } } void OnSoundSourceAuralizationModeChanged(string AuraMode)