Skip to content

Commit e7b1d6a

Browse files
committed
fix:(Sound): Audio source inaccesible
1 parent 8b327e4 commit e7b1d6a

File tree

10 files changed

+32
-33
lines changed

10 files changed

+32
-33
lines changed

Assets/JCSUnity/Scripts/Actions/2D/AI/AIMoveAction/JCS_2DFlyAction.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,13 @@ private void SpaceLimitCheck()
495495
/// </summary>
496496
private void PlayFlySound()
497497
{
498-
// play fly sound,
498+
if (mSoundPlayer == null)
499+
return;
500+
499501
// fly sound should be looped.
500-
if (mSoundPlayer != null)
501-
{
502-
mSoundPlayer.GetAudioSource().loop = true;
503-
mSoundPlayer.GetAudioSource().clip = mFlySound;
504-
mSoundPlayer.GetAudioSource().Play();
505-
}
502+
mSoundPlayer.audioSource.loop = true;
503+
mSoundPlayer.audioSource.clip = mFlySound;
504+
mSoundPlayer.audioSource.Play();
506505
}
507506

508507
}

Assets/JCSUnity/Scripts/Effects/Particle/JCS_ParticleSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace JCSUnity
1414
/// <summary>
1515
/// Particle System thats spawns `JCS_Particle` object.
1616
/// </summary>
17-
[RequireComponent(typeof(JCS_EnvironmentSoundPlayer))]
17+
[RequireComponent(typeof(JCS_EnvSoundPlayer))]
1818
public class JCS_ParticleSystem : MonoBehaviour
1919
{
2020
/* Variables */

Assets/JCSUnity/Scripts/Effects/Particle/Weather/JCS_EnvironmentSoundPlayer.cs renamed to Assets/JCSUnity/Scripts/Effects/Particle/Weather/JCS_EnvSoundPlayer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace JCSUnity
1414
/// <summary>
1515
/// Sound player specific for environment sound.
1616
/// </summary>
17-
public class JCS_EnvironmentSoundPlayer : JCS_SoundPlayer
17+
public class JCS_EnvSoundPlayer : JCS_SoundPlayer
1818
{
1919
/* Variables */
2020

21-
[Separator("Initialize Variables (JCS_EnvironmentSoundPlayer)")]
21+
[Separator("Initialize Variables (JCS_EnvSoundPlayer)")]
2222

2323
[Tooltip("Sound to play for environment sound.")]
2424
[SerializeField]
25-
private AudioClip mEnvironmentSound = null;
25+
private AudioClip mEnvSound = null;
2626

2727
/* Setter & Getter */
2828

@@ -32,11 +32,11 @@ protected override void Awake()
3232
{
3333
base.Awake();
3434

35-
GetAudioSource().loop = true;
35+
mAudioSource.loop = true;
3636

3737
// NOTE(JenChieh): does not connect to bgm yet.
38-
GetAudioSource().clip = mEnvironmentSound;
39-
GetAudioSource().Play();
38+
mAudioSource.clip = mEnvSound;
39+
mAudioSource.Play();
4040
}
4141
}
4242
}

Assets/JCSUnity/Scripts/Effects/Particle/Weather/JCS_EnvironmentSoundPlayer.cs.meta renamed to Assets/JCSUnity/Scripts/Effects/Particle/Weather/JCS_EnvSoundPlayer.cs.meta

File renamed without changes.

Assets/JCSUnity/Scripts/Events/Destroy/JCS_DestroySoundEndEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public void SetAudioClipAndPlayOneShot(AudioClip clip)
2727
if (mSoundPlayer == null)
2828
mSoundPlayer = this.GetComponent<JCS_SoundPlayer>();
2929

30-
this.mSoundPlayer.GetAudioSource().clip = clip;
30+
this.mSoundPlayer.audioSource.clip = clip;
3131
this.mSoundPlayer.PlayOneShot(clip);
3232
}
3333

3434
/* Functions */
3535

3636
private void Update()
3737
{
38-
if (mSoundPlayer.GetAudioSource().isPlaying)
38+
if (mSoundPlayer.audioSource.isPlaying)
3939
return;
4040

4141
Destroy(this.gameObject);

Assets/JCSUnity/Scripts/GameObject/2D/2DAudioController/JCS_2DSideScrollerPlayerAudioController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void AttackSound()
100100
if (!mOverrideSound)
101101
{
102102
// do not override the sound
103-
if (mSoundPlayer.GetAudioSource().isPlaying)
103+
if (mSoundPlayer.audioSource.isPlaying)
104104
return;
105105
}
106106

Assets/JCSUnity/Scripts/Managers/JCS_SceneManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private void Start()
181181
if (mFadeSound == null)
182182
mFadeSound = this.gameObject.AddComponent<JCS_FadeSound>();
183183

184-
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.GetAudioSource();
184+
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.audioSource;
185185

186186
// set the background audio source.
187187
mFadeSound.SetAudioSource(
@@ -393,7 +393,7 @@ public void LoadScene(string sceneName, float fadeInTime, Color screenColor, boo
393393
if (mFadeSound == null)
394394
mFadeSound = this.gameObject.AddComponent<JCS_FadeSound>();
395395

396-
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.GetAudioSource();
396+
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.audioSource;
397397

398398
mFadeSound.SetAudioSource(bgmAudioSource);
399399

Assets/JCSUnity/Scripts/Managers/JCS_SoundManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void SwitchBGM(
176176
}
177177

178178
// get the background music audio source.
179-
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.GetAudioSource();
179+
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.audioSource;
180180

181181
// check if loop
182182
bgmAudioSource.loop = loop;
@@ -295,7 +295,7 @@ private void DoSwitchBGM()
295295
return;
296296

297297
// get the background music audio source.
298-
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.GetAudioSource();
298+
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.audioSource;
299299

300300
// set the audio source.
301301
mJCSFadeSound.SetAudioSource(bgmAudioSource);
@@ -338,7 +338,7 @@ private void DoStackBGM()
338338
if (mSwitchingBGM)
339339
return;
340340

341-
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.GetAudioSource();
341+
AudioSource bgmAudioSource = JCS_BGMPlayer.instance.audioSource;
342342

343343
// do nothing if still playing
344344
if (bgmAudioSource.isPlaying)

Assets/JCSUnity/Scripts/Sound/JCS_BGMPlayer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using UnityEngine;
910
using UnityEngine.SceneManagement;
1011

1112
namespace JCSUnity
@@ -67,16 +68,16 @@ private void LevelLoaded()
6768
{
6869
// In 2023.2.19f1, the loop will be turned off for some reason.
6970
// Let's force BGM to run loop!
70-
GetAudioSource().loop = true;
71+
mAudioSource.loop = true;
7172

7273
var ss = JCS_SoundSettings.instance;
7374

7475
if (!ss.KEEP_BGM_SWITCH_SCENE)
7576
{
7677
// Assign BGM from Sound Manager!
77-
GetAudioSource().clip = ss.BACKGROUND_MUSIC;
78+
mAudioSource.clip = ss.BACKGROUND_MUSIC;
7879

79-
GetAudioSource().Play();
80+
mAudioSource.Play();
8081
}
8182
}
8283
}

Assets/JCSUnity/Scripts/Sound/JCS_SoundPlayer.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
99
using UnityEngine;
10-
using MyBox;
1110

1211
namespace JCSUnity
1312
{
@@ -20,11 +19,11 @@ public class JCS_SoundPlayer : MonoBehaviour
2019
{
2120
/* Variables */
2221

23-
private AudioSource mAudioSource = null;
22+
protected AudioSource mAudioSource = null;
2423

2524
/* Setter & Getter */
2625

27-
public AudioSource GetAudioSource() { return this.mAudioSource; }
26+
public AudioSource audioSource { get { return mAudioSource; } }
2827

2928
/* Functions */
3029

@@ -67,18 +66,18 @@ public void PlayOneShot(AudioClip clip, float volume = 1.0f)
6766
if (clip == null)
6867
return;
6968

70-
GetAudioSource().PlayOneShot(clip, volume);
69+
mAudioSource.PlayOneShot(clip, volume);
7170
}
7271

7372
/// <summary>
7473
/// play sound when is not playing any sound.
7574
/// </summary>
7675
public void PlayOneShotWhileNotPlaying(AudioClip clip, float volume = 1.0f)
7776
{
78-
if (GetAudioSource() == null)
77+
if (mAudioSource == null)
7978
return;
8079

81-
if (GetAudioSource().isPlaying)
80+
if (mAudioSource.isPlaying)
8281
return;
8382

8483
PlayOneShot(clip, volume);
@@ -89,10 +88,10 @@ public void PlayOneShotWhileNotPlaying(AudioClip clip, float volume = 1.0f)
8988
/// </summary>
9089
public void PlayOneShotInterrupt(AudioClip clip, float volume = 1.0f)
9190
{
92-
if (GetAudioSource() == null)
91+
if (mAudioSource == null)
9392
return;
9493

95-
GetAudioSource().Stop();
94+
mAudioSource.Stop();
9695

9796
PlayOneShot(clip, volume);
9897
}

0 commit comments

Comments
 (0)