VAUSignalSourceAudioFile.cs 1.13 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
    void Awake()
    {
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
17 18 19
        if (!VAUAdapter.VA.IsConnected())
            return;

20
        _ID = VAUAdapter.VA.CreateSignalSourceBufferFromFile(FilePath, Name);
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
21
        Debug.Assert(_ID.Length > 0, "Could not create audio file signal source '" + Name + "' file from path " + FilePath);
22
    }
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
23
    
24 25
    void Start()
    {
26
        VAUAdapter.VA.SetSignalSourceBufferLooping(_ID, IsLooping);
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
27
        if (PlayOnStart)
28
            VAUAdapter.VA.SetSignalSourceBufferPlaybackAction(_ID, "PLAY");
29
    }
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
30 31 32 33 34 35

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