VAUSoundSource.cs 2.18 KB
Newer Older
1 2 3 4 5 6 7
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using VA;

public class VAUSoundSource : MonoBehaviour {
8
    
9
    public int AuralizationMode = 1;
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
10
    [Range(0.0f, 10.0f)]
11
    public int Volume = 1;
12
    public string SignalSource = "";
13 14
    private VANet _VA = null;
    private int SoundSource;
15 16
    private Vector3 viewvec = new Vector3(0, 0, 1);
    private Vector3 upvec = new Vector3(0, 1, 0);
17 18
    private Quaternion q;
    private Transform t;
19 20
    private bool islooping;
    private bool ismuted;
21 22 23 24

    // Use this for initialization
    void Start()
    {
25 26 27
        _VA = VAUAdapter.VA;
        SoundSource = _VA.CreateSoundSource(this.name, AuralizationMode, Volume);
        islooping = GetComponent<AudioSource>().loop;
28 29 30 31
        if (GetComponent<AudioSource>() != null)
        {
            SignalSource = _VA.CreateAudiofileSignalSource( AssetDatabase.GetAssetPath(GetComponent<AudioSource>().clip), this.name + "_signal");
            _VA.SetSoundSourceSignalSource(SoundSource, SignalSource);
32
            Debug.Log(SignalSource + " connected to SoundSource " + SoundSource);
33
            _VA.SetAudiofileSignalSourcePlaybackAction(SignalSource, 2);
34
            _VA.SetAudiofileSignalSourceIsLooping(SignalSource, islooping);
35 36 37 38 39 40 41
        }
    }

    // Update is called once per frame
    void Update()
    {
        //position and oritentation -> VA
42 43 44 45 46 47 48
        t = GetComponent<Transform>();
        q = t.rotation;
        Vector3 up = q * upvec;
        Vector3 view = q * viewvec;
        Vector3 view_ogl = new Vector3(view.x, view.y, -view.z);
        Vector3 up_ogl = new Vector3(up.x, up.y, -up.z);

49
        _VA.SetSoundSourcePosition(SoundSource, t.transform.position.x, t.transform.position.y, -t.transform.position.z);
50
        _VA.SetSoundSourceOrientationVU(SoundSource, view_ogl.x, view_ogl.y, view_ogl.z, up_ogl.x, up_ogl.y, up_ogl.z);
51 52
        ismuted = GetComponent<AudioSource>().mute;
        _VA.SetSoundSourceMuted(SoundSource, ismuted);
53
        //_VA.SetSoundSourceVolume(SoundSource, Volume); <- flaot ändern
54 55 56
        
    }

57 58 59 60 61
    void OnDestroy()
    {
        _VA.DeleteSoundSource(SoundSource);
        //_VA.DeleteSignalSource(SignalSource);
    }
62 63

}