2019-11-08 13:54:45 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Behaviours.Vehicles
|
|
|
|
|
{
|
|
|
|
|
public partial class Vehicle
|
|
|
|
|
{
|
|
|
|
|
private int currentRadioStationIndex;
|
|
|
|
|
private RadioStation CurrentRadioStation { get { return RadioStation.stations[currentRadioStationIndex]; } }
|
|
|
|
|
|
2019-11-18 14:56:12 +01:00
|
|
|
|
private AudioSource m_radioAudioSource;
|
2019-11-08 13:54:45 +02:00
|
|
|
|
|
|
|
|
|
public void PlayRadio()
|
|
|
|
|
{
|
2019-11-18 14:56:12 +01:00
|
|
|
|
m_radioAudioSource.Stop();
|
2019-11-18 15:21:13 +01:00
|
|
|
|
|
|
|
|
|
// destroy current clip
|
|
|
|
|
if (m_radioAudioSource.clip != null)
|
|
|
|
|
{
|
|
|
|
|
Destroy(m_radioAudioSource.clip);
|
|
|
|
|
m_radioAudioSource.clip = null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-18 15:08:57 +01:00
|
|
|
|
var clip = CurrentRadioStation.LoadCurrentClip();
|
2019-11-08 13:54:45 +02:00
|
|
|
|
if (clip != null)
|
|
|
|
|
{
|
2019-11-18 14:56:12 +01:00
|
|
|
|
m_radioAudioSource.time = CurrentRadioStation.currentTime;
|
|
|
|
|
m_radioAudioSource.clip = clip;
|
|
|
|
|
m_radioAudioSource.Play();
|
2019-11-08 13:54:45 +02:00
|
|
|
|
|
|
|
|
|
Destroy(clip, clip.length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ContinueRadio()
|
|
|
|
|
{
|
|
|
|
|
CurrentRadioStation.NextClip();
|
|
|
|
|
PlayRadio();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SwitchRadioStation(bool next)
|
|
|
|
|
{
|
|
|
|
|
if (currentRadioStationIndex != -1)
|
|
|
|
|
{
|
2019-11-18 14:56:12 +01:00
|
|
|
|
CurrentRadioStation.currentTime = m_radioAudioSource.time;
|
2019-11-08 13:54:45 +02:00
|
|
|
|
}
|
2019-11-18 15:08:57 +01:00
|
|
|
|
|
2019-11-08 13:54:45 +02:00
|
|
|
|
if (next)
|
|
|
|
|
{
|
|
|
|
|
currentRadioStationIndex++;
|
|
|
|
|
if (currentRadioStationIndex >= RadioStation.stations.Length)
|
|
|
|
|
currentRadioStationIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRadioStationIndex--;
|
|
|
|
|
if (currentRadioStationIndex < -1)
|
|
|
|
|
currentRadioStationIndex = RadioStation.stations.Length - 1;
|
|
|
|
|
}
|
2019-11-18 15:08:57 +01:00
|
|
|
|
|
2019-11-08 13:54:45 +02:00
|
|
|
|
if (currentRadioStationIndex == -1)
|
|
|
|
|
{
|
2019-11-18 14:56:12 +01:00
|
|
|
|
m_radioAudioSource.Stop();
|
2019-11-08 13:54:45 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PlayRadio();
|
|
|
|
|
}
|
2019-11-18 15:08:57 +01:00
|
|
|
|
|
2019-11-08 13:54:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|