VAUSoundSource.cs 2.51 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;
10 11 12
    public string directivitypath = "";
    private int directivity;
    private int Gain = 1;
13
    public string SignalSource = "";
14 15
    private VANet _VA = null;
    private int SoundSource;
16 17
    private Quaternion q;
    private Transform t;
18 19
    private bool islooping;
    private bool ismuted;
20

21 22 23 24 25 26 27 28
    public int ID
    {
        get
        {
            return SoundSource;
        }
    }

29 30 31
    // Use this for initialization
    void Start()
    {
32
        _VA = VAUAdapter.VA;
33
        SoundSource = _VA.CreateSoundSource(this.name, AuralizationMode, Gain);
34
        islooping = GetComponent<AudioSource>().loop;
35 36 37 38
        if (directivitypath == "")
            directivity = VAUAdapter.DefaultDirectivity;
        else
            directivity = _VA.LoadDirectivity(directivitypath, "SoundSource " + SoundSource + " Directivity");
39 40 41 42
        if (GetComponent<AudioSource>() != null)
        {
            SignalSource = _VA.CreateAudiofileSignalSource( AssetDatabase.GetAssetPath(GetComponent<AudioSource>().clip), this.name + "_signal");
            _VA.SetSoundSourceSignalSource(SoundSource, SignalSource);
43
            Debug.Log(SignalSource + " connected to SoundSource " + SoundSource);
44
            _VA.SetAudiofileSignalSourcePlaybackAction(SignalSource, 2);
45
            _VA.SetAudiofileSignalSourceIsLooping(SignalSource, islooping);
46 47 48 49 50 51 52
        }
    }

    // Update is called once per frame
    void Update()
    {
        //position and oritentation -> VA
53 54
        t = GetComponent<Transform>();
        q = t.rotation;
55 56
        Vector3 up = q * Vector3.up;
        Vector3 view = q * Vector3.forward;
57 58 59
        Vector3 view_ogl = new Vector3(view.x, view.y, -view.z);
        Vector3 up_ogl = new Vector3(up.x, up.y, -up.z);

60 61 62
        _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);
        //_VA.SetSoundSourceOrientationVU(SoundSource, view_ogl.x, view_ogl.y, view_ogl.z, up_ogl.x, up_ogl.y, up_ogl.z);
        //_VA.SetSoundSourcePosition(SoundSource, t.transform.position.x, t.transform.position.y, -t.transform.position.z);
63 64
        ismuted = GetComponent<AudioSource>().mute;
        _VA.SetSoundSourceMuted(SoundSource, ismuted);
65
        //_VA.SetSoundSourceVolume(SoundSource, Volume); <- flaot ändern
66 67 68
        
    }
}