VAUSignalSourceAudioFile.cs 1.37 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
    void Awake()
    {
        if (!VAUAdapter.VA.IsConnected())
		{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
19
			Debug.LogError( "Could not awake signal source '" + FilePath + "', not connected to VA" );
20 21 22 23
            return;
		}
	}
	
24 25
    void OnEnable()
	{		
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
26 27 28 29 30
		if (!VAUAdapter.VA.IsConnected())
		{
			Debug.LogError( "Could not enable signal source '" + FilePath + "', not connected to VA" );
			return;
		}
31 32 33 34 35 36 37
		_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
38
        if (PlayOnStart)
39
            VAUAdapter.VA.SetSignalSourceBufferPlaybackAction(_ID, "PLAY");
40
    }
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
41 42 43 44 45 46

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