Files

102 lines
2.3 KiB
C#
Raw Permalink Normal View History

2023-06-20 13:17:31 -05:00
using UnityEngine;
namespace SmartPoint.Components
{
public class AudioChannel
{
2023-07-01 21:07:29 -05:00
private AudioSource _source;
private float _volume;
private int _type;
private int _status;
private float _duration;
private float _elapsedTime;
public AudioChannel(int type, AudioSource source)
{
_volume = 1.0f;
_type = type;
_source = source;
ResetVolume();
}
public void ResetVolume()
{
float volume;
switch (_type)
{
case 3:
volume = AudioPlayer.GlobalVoiceVolume;
break;
case 2:
volume = AudioPlayer.GlobalEffectVolume;
break;
case 1:
volume = AudioPlayer.GlobalStreamVolume;
break;
default:
volume = 0.0f;
break;
}
_source.volume = volume * _volume;
}
2023-06-20 13:17:31 -05:00
public AudioClip Clip
{
2023-07-01 21:07:29 -05:00
get => _source ? _source.clip : null;
2023-06-20 13:17:31 -05:00
set
{
2023-07-01 21:07:29 -05:00
if (_source)
_source.clip = value;
2023-06-20 13:17:31 -05:00
}
}
public float Time
{
2023-07-01 21:07:29 -05:00
get => _source ? _source.time : 0.0f;
2023-06-20 13:17:31 -05:00
set
{
2023-07-01 21:07:29 -05:00
if (_source)
_source.time = value;
2023-06-20 13:17:31 -05:00
}
}
public float Volume
{
2023-07-01 21:07:29 -05:00
get => _volume;
2023-06-20 13:17:31 -05:00
set
{
_volume = value;
ResetVolume();
}
}
2023-07-01 21:07:29 -05:00
public bool IsPlaying => _source && _source.isPlaying;
2023-06-20 13:17:31 -05:00
2023-07-01 21:07:29 -05:00
public void Play() => _status = 2;
public void Stop() => _status = 7;
public void Pause() => _status = 4;
public AudioSource Source => _source;
2023-06-20 13:17:31 -05:00
public int Status
{
2023-07-01 21:07:29 -05:00
get => _status;
set => _status = value;
2023-06-20 13:17:31 -05:00
}
public float Duration
{
2023-07-01 21:07:29 -05:00
get => _duration;
set => _duration = value;
2023-06-20 13:17:31 -05:00
}
public float ElapsedTime
{
2023-07-01 21:07:29 -05:00
get => _elapsedTime;
set => _elapsedTime = value;
2023-06-20 13:17:31 -05:00
}
}
}