Skip to content

Commit 51cf379

Browse files
committed
refactor(Util): Improve spawn clip and particle system call
1 parent d519a6d commit 51cf379

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Audio.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,24 @@ public static AudioSource PlayClipAtPoint(
9797
/// <summary>
9898
/// Destroy the clip by its clip length.
9999
/// </summary>
100-
public static void DestroyClip(AudioSource source)
100+
public static bool DestroyClip(AudioSource source)
101101
{
102-
DestroyClip(source, source.clip);
102+
return DestroyClip(source, source.clip);
103103
}
104-
public static void DestroyClip(AudioSource source, AudioClip clip)
104+
public static bool DestroyClip(AudioSource source, AudioClip clip)
105+
{
106+
float duration = clip.length * ((Time.timeScale < 0.01f) ? 0.01f : Time.timeScale);
107+
108+
return DestroyClip(source, duration);
109+
}
110+
public static bool DestroyClip(AudioSource source, float duration)
105111
{
106112
if (source.loop)
107-
return;
113+
return false;
114+
115+
Object.Destroy(source.gameObject, duration);
108116

109-
Object.Destroy(source.gameObject, clip.length * ((Time.timeScale < 0.01f) ? 0.01f : Time.timeScale));
117+
return true;
110118
}
111119
}
112120
}

Assets/JCSUnity/Scripts/Util/JCS_Util.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,16 +1195,18 @@ public static ParticleSystem PlayParticleAtPoint(ParticleSystem ps, Vector3 posi
11951195
/// <summary>
11961196
/// Destroy the particle by its duration.
11971197
/// </summary>
1198-
public static void DestroyParticle(ParticleSystem ps)
1198+
public static bool DestroyParticle(ParticleSystem ps)
11991199
{
1200-
DestroyParticle(ps, ps.main.duration);
1200+
return DestroyParticle(ps, ps.main.duration);
12011201
}
1202-
public static void DestroyParticle(ParticleSystem ps, float duration)
1202+
public static bool DestroyParticle(ParticleSystem ps, float duration)
12031203
{
12041204
if (ps.main.loop)
1205-
return;
1205+
return false;
12061206

12071207
Object.Destroy(ps.gameObject, duration);
1208+
1209+
return true;
12081210
}
12091211

12101212
#endregion

0 commit comments

Comments
 (0)