VAUSignalSourceAudioFile.cs 1.23 KB
Newer Older
1 2 3 4
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
5
public class VAUSignalSourceAudioFile : VAUSignalSource
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
6
{
7 8
    [Tooltip("Absolute or relative file path (relative to Assets folder or any folder added to search path using AddSearchPath)")]
    public string FilePath;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
9
    public string Name; // Versatile name
10 11 12 13
    [Tooltip("Will loop the audio signal source.")]
    public bool IsLooping = true;  
    [Tooltip("Will immediately start the signal source payback.")]
    public bool PlayOnStart = true; 
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
14
    
15 16 17 18 19 20 21 22 23
    void Awake()
    {
        if (!VAUAdapter.VA.IsConnected())
		{
			Debug.LogError( 'Could not create signal source "' + FilePath + '", not connected to VA' );
            return;
		}
	}
	
24 25 26 27 28 29 30 31 32
    void OnEnable()
	{		
		_ID = VAUAdapter.VA.CreateSignalSourceBufferFromFile (FilePath, Name);
		Debug.Assert (_ID.Length > 0, "Could not create audio file signal source '" + Name + "' from file path " + FilePath);
		VAUAdapter.VA.SetSignalSourceBufferLooping (_ID, IsLooping);
	}

	void Start()
	{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
33
        if (PlayOnStart)
34
            VAUAdapter.VA.SetSignalSourceBufferPlaybackAction(_ID, "PLAY");
35
    }
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
36 37 38 39 40 41

    void OnDestroy()
    {
        if (_ID.Length > 0)
            VAUAdapter.VA.DeleteSignalSource(_ID);
    }
42
}