HeavenStudioPlus/Assets/Scripts/Util/Jukebox.cs

62 lines
1.8 KiB
C#
Raw Normal View History

2021-12-21 01:10:49 +00:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Util
{
public class Jukebox
{
public enum AudioType
{
OGG,
WAV
}
/// <summary>
/// This is me just idiot-proofing.
/// </summary>
public static void BasicCheck()
{
if (FindJukebox() == null)
{
GameObject Jukebox = new GameObject("Jukebox");
Jukebox.AddComponent<AudioSource>();
Jukebox.tag = "Jukebox";
}
}
public static GameObject FindJukebox()
{
if (GameObject.FindGameObjectWithTag("Jukebox") != null)
return GameObject.FindGameObjectWithTag("Jukebox");
else
return null;
}
public static void SetVolume(float volume)
{
BasicCheck();
FindJukebox().GetComponent<AudioSource>().volume = volume;
}
public static void PlayOneShot(string name, bool relyOnBeat = true)
2021-12-21 01:10:49 +00:00
{
GameObject oneShot = new GameObject("oneShot");
AudioSource aus = oneShot.AddComponent<AudioSource>();
aus.playOnAwake = false;
Sound snd = oneShot.AddComponent<Sound>();
snd.relyOnBeat = relyOnBeat;
2022-01-15 07:08:23 +00:00
AudioClip clip = Resources.Load<AudioClip>($"Sfx/{name}");
snd.clip = clip;
// snd.pitch = (clip.length / Conductor.instance.secPerBeat);
2021-12-21 01:10:49 +00:00
}
2021-12-23 22:39:03 +00:00
public static void PlayOneShotGame(string name, bool relyOnBeat = true)
2021-12-23 22:39:03 +00:00
{
if (GameManager.instance.currentGame == name.Split('/')[0])
PlayOneShot($"games/{name}", relyOnBeat);
2021-12-23 22:39:03 +00:00
}
2021-12-21 01:10:49 +00:00
}
}