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;
|
|
|
|
}
|
|
|
|
|
2022-02-11 07:21:43 +00:00
|
|
|
public static AudioSource PlayOneShot(string name, float beat = -1)
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
|
|
|
GameObject oneShot = new GameObject("oneShot");
|
2022-01-21 01:24:30 +00:00
|
|
|
|
|
|
|
AudioSource audioSource = oneShot.AddComponent<AudioSource>();
|
2022-02-05 04:40:33 +00:00
|
|
|
//audioSource.outputAudioMixerGroup = Settings.GetSFXMixer();
|
2022-01-21 01:24:30 +00:00
|
|
|
audioSource.playOnAwake = false;
|
|
|
|
|
2021-12-21 01:10:49 +00:00
|
|
|
Sound snd = oneShot.AddComponent<Sound>();
|
2022-01-15 07:08:23 +00:00
|
|
|
AudioClip clip = Resources.Load<AudioClip>($"Sfx/{name}");
|
|
|
|
snd.clip = clip;
|
2022-01-21 01:24:30 +00:00
|
|
|
snd.beat = beat;
|
2022-01-15 07:08:23 +00:00
|
|
|
// snd.pitch = (clip.length / Conductor.instance.secPerBeat);
|
2022-01-21 01:24:30 +00:00
|
|
|
|
|
|
|
GameManager.instance.SoundObjects.Add(oneShot);
|
2022-02-11 07:21:43 +00:00
|
|
|
|
|
|
|
return audioSource;
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
2021-12-23 22:39:03 +00:00
|
|
|
|
2022-02-11 07:21:43 +00:00
|
|
|
public static AudioSource PlayOneShotScheduled(string name, double targetTime)
|
2022-02-05 13:08:33 +00:00
|
|
|
{
|
|
|
|
GameObject oneShot = new GameObject("oneShotScheduled");
|
|
|
|
|
|
|
|
var audioSource = oneShot.AddComponent<AudioSource>();
|
|
|
|
audioSource.playOnAwake = false;
|
|
|
|
|
|
|
|
var snd = oneShot.AddComponent<Sound>();
|
|
|
|
|
|
|
|
var clip = Resources.Load<AudioClip>($"Sfx/{name}");
|
|
|
|
audioSource.clip = clip;
|
|
|
|
snd.clip = clip;
|
|
|
|
|
|
|
|
snd.scheduled = true;
|
|
|
|
snd.scheduledTime = targetTime;
|
|
|
|
audioSource.PlayScheduled(targetTime);
|
|
|
|
|
|
|
|
GameManager.instance.SoundObjects.Add(oneShot);
|
2022-02-11 07:21:43 +00:00
|
|
|
|
|
|
|
return audioSource;
|
2022-02-05 13:08:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 07:21:43 +00:00
|
|
|
public static AudioSource PlayOneShotGame(string name, float beat = -1)
|
2021-12-23 22:39:03 +00:00
|
|
|
{
|
2021-12-26 01:04:23 +00:00
|
|
|
if (GameManager.instance.currentGame == name.Split('/')[0])
|
2022-01-21 01:24:30 +00:00
|
|
|
{
|
2022-02-11 07:21:43 +00:00
|
|
|
return PlayOneShot($"games/{name}", beat);
|
2022-01-21 01:24:30 +00:00
|
|
|
}
|
2022-02-11 07:21:43 +00:00
|
|
|
|
|
|
|
return null;
|
2021-12-23 22:39:03 +00:00
|
|
|
}
|
2022-02-05 13:08:33 +00:00
|
|
|
|
2022-02-11 07:21:43 +00:00
|
|
|
public static AudioSource PlayOneShotScheduledGame(string name, double targetTime)
|
2022-02-05 13:08:33 +00:00
|
|
|
{
|
|
|
|
if (GameManager.instance.currentGame == name.Split('/')[0])
|
|
|
|
{
|
2022-02-11 07:21:43 +00:00
|
|
|
return PlayOneShotScheduled($"games/{name}", targetTime);
|
2022-02-05 13:08:33 +00:00
|
|
|
}
|
2022-02-11 07:21:43 +00:00
|
|
|
|
|
|
|
return null;
|
2022-02-05 13:08:33 +00:00
|
|
|
}
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|