mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-16 21:08:28 +00:00
destroy radio clip when stopping radio sound ; destroy radio clip when vehicle gets destroyed ;
This commit is contained in:
parent
bb7330f9ac
commit
8e8e495633
2 changed files with 20 additions and 6 deletions
|
@ -185,6 +185,8 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
||||||
void OnDisable()
|
void OnDisable()
|
||||||
{
|
{
|
||||||
s_vehicles.Remove(this);
|
s_vehicles.Remove(this);
|
||||||
|
|
||||||
|
this.OnDisable_Radio();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
|
|
|
@ -31,6 +31,12 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
||||||
m_currentRadioStationIndex = Random.Range(0, RadioStation.stations.Length);
|
m_currentRadioStationIndex = Random.Range(0, RadioStation.stations.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnDisable_Radio()
|
||||||
|
{
|
||||||
|
// need to destroy audio clip here, because otherwise it will stay in memory
|
||||||
|
this.StopPlayingRadio();
|
||||||
|
}
|
||||||
|
|
||||||
void Start_Radio()
|
void Start_Radio()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -129,6 +135,8 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
||||||
RadioStation.stations[m_currentRadioStationIndex].currentTime = m_radioAudioSource.time;
|
RadioStation.stations[m_currentRadioStationIndex].currentTime = m_radioAudioSource.time;
|
||||||
|
|
||||||
m_radioAudioSource.Stop();
|
m_radioAudioSource.Stop();
|
||||||
|
|
||||||
|
this.DestroyCurrentRadioClip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartPlayingRadio(bool playImmediately)
|
void StartPlayingRadio(bool playImmediately)
|
||||||
|
@ -175,12 +183,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
||||||
|
|
||||||
m_radioAudioSource.Stop(); // just in case
|
m_radioAudioSource.Stop(); // just in case
|
||||||
|
|
||||||
// destroy current clip
|
this.DestroyCurrentRadioClip();
|
||||||
if (m_radioAudioSource.clip != null)
|
|
||||||
{
|
|
||||||
Destroy(m_radioAudioSource.clip);
|
|
||||||
m_radioAudioSource.clip = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var clip = RadioStation.stations[m_currentRadioStationIndex].LoadCurrentClip();
|
var clip = RadioStation.stations[m_currentRadioStationIndex].LoadCurrentClip();
|
||||||
if (clip != null)
|
if (clip != null)
|
||||||
|
@ -194,6 +197,15 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DestroyCurrentRadioClip()
|
||||||
|
{
|
||||||
|
if (m_radioAudioSource.clip != null)
|
||||||
|
{
|
||||||
|
Destroy(m_radioAudioSource.clip);
|
||||||
|
m_radioAudioSource.clip = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SwitchRadioStation(bool next)
|
public void SwitchRadioStation(bool next)
|
||||||
{
|
{
|
||||||
int index = m_currentRadioStationIndex;
|
int index = m_currentRadioStationIndex;
|
||||||
|
|
Loading…
Add table
Reference in a new issue