using UnityEngine; using UnityEditor; using System.Collections; using System.Collections.Generic; using VA; public class VAUSoundSource : MonoBehaviour { public string directivitypath = ""; private int directivity; private int Gain = 1; private string SignalSource = ""; private VANet _VA = null; private int SoundSource; private Quaternion q; private Transform t; private bool islooping; private bool ismuted; public int ID { get { return SoundSource; } } public string SignalSourceID { get { return SignalSource; } } // Use this for initialization void Start() { _VA = VAUAdapter.VA; SoundSource = _VA.CreateSoundSource(this.name, 0, Gain); _VA.SetSoundSourceAuralizationMode(SoundSource, "all"); islooping = GetComponent().loop; if (directivitypath == "") directivity = VAUAdapter.DefaultDirectivity; else directivity = _VA.LoadDirectivity(directivitypath, "SoundSource " + SoundSource + " Directivity"); if (GetComponent() != null) { SignalSource = _VA.CreateAudiofileSignalSource( AssetDatabase.GetAssetPath(GetComponent().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() != null) { GetComponent().AuraStringChanged += OnSoundSourceAuralizationModeChanged; } } // Update is called once per frame void Update() { SetSoundSourcePosition(); SetSoundSourcePlaybackState(); //_VA.SetSoundSourceVolume(SoundSource, Volume); <- flaot ändern } void SetSoundSourcePosition() { //position and oritentation -> VA t = GetComponent(); q = t.rotation; Vector3 up = q * Vector3.up; 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.SetSoundSourcePositionOrientationVU(SoundSource, t.transform.position.x, t.transform.position.y, -t.transform.position.z, view_ogl.x, view_ogl.y, view_ogl.z, up_ogl.x, up_ogl.y, up_ogl.z); } void SetSoundSourcePlaybackState() { _VA.SetSoundSourceMuted(SoundSource, GetComponent().mute); } void OnSoundSourceAuralizationModeChanged(string AuraMode) { _VA.SetSoundSourceAuralizationMode(SoundSource, AuraMode); } public void OnDisable() { if (GetComponent() != null) GetComponent().AuraStringChanged -= OnSoundSourceAuralizationModeChanged; } void OnDestroy() { if (_VA.IsConnected()) { _VA.DeleteSoundSource(SoundSource); } } }