Commit a4f4ddf4 authored by Maurice Tayeb Andreas's avatar Maurice Tayeb Andreas

Einige Verschönerungen, die Abstürze vorbeugen sollten.

VAUAdapter deaktiviert nun alle aktiven AudioSources, sodass dies nicht mehr manuell getan werden muss.
parent 7a002e9b
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;
}
......
......@@ -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;
}
}
}
......@@ -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)
......
......@@ -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)
......
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