VAUSoundSource.cs 1.87 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 15 16
    private VANet _VA = null;
    private int SoundSource;
    private bool islooping;
    private bool ismuted;
17 18 19 20

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

    // Update is called once per frame
    void Update()
    {
        //position and oritentation -> VA
        Transform t = GetComponent<Transform>();
        _VA.SetSoundSourcePosition(SoundSource, t.transform.position.x, t.transform.position.y, -t.transform.position.z);
        _VA.SetSoundSourceOrientationYPR(SoundSource, -t.transform.rotation.eulerAngles.x, -t.transform.rotation.y, t.transform.rotation.eulerAngles.z);
41 42
        ismuted = GetComponent<AudioSource>().mute;
        _VA.SetSoundSourceMuted(SoundSource, ismuted);
43
        //_VA.SetSoundSourceVolume(SoundSource, Volume); <- flaot ändern
44 45 46
        
    }

47 48 49 50 51
    //void OnDestroy()
    //{
    //    //_VA.DeleteSoundSource(SoundSource);
    //    //_VA.DeleteSignalSource(SignalSource);
    //}
52 53

}