mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 20:13:02 +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()
|
||||
{
|
||||
s_vehicles.Remove(this);
|
||||
|
||||
this.OnDisable_Radio();
|
||||
}
|
||||
|
||||
void Start()
|
||||
|
|
|
@ -31,6 +31,12 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
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()
|
||||
{
|
||||
|
||||
|
@ -129,6 +135,8 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
RadioStation.stations[m_currentRadioStationIndex].currentTime = m_radioAudioSource.time;
|
||||
|
||||
m_radioAudioSource.Stop();
|
||||
|
||||
this.DestroyCurrentRadioClip();
|
||||
}
|
||||
|
||||
void StartPlayingRadio(bool playImmediately)
|
||||
|
@ -175,12 +183,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
|
||||
m_radioAudioSource.Stop(); // just in case
|
||||
|
||||
// destroy current clip
|
||||
if (m_radioAudioSource.clip != null)
|
||||
{
|
||||
Destroy(m_radioAudioSource.clip);
|
||||
m_radioAudioSource.clip = null;
|
||||
}
|
||||
this.DestroyCurrentRadioClip();
|
||||
|
||||
var clip = RadioStation.stations[m_currentRadioStationIndex].LoadCurrentClip();
|
||||
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)
|
||||
{
|
||||
int index = m_currentRadioStationIndex;
|
||||
|
|
Loading…
Reference in a new issue