Created
November 2, 2017 18:22
-
-
Save tatmos/312786f8def6428a909afd8a9fbb5b1c to your computer and use it in GitHub Desktop.
2016福島ゲームジャム FootSteps ( https://www.youtube.com/watch?v=eYanv0k8pwU )でのSoundManager。ADX2LEでセレクタラベルで音楽切り替え。マルチシーン対応( https://qiita.com/tatmos/items/b0dffe4075aa5af3efd5 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.SceneManagement; | |
public class SoundManager : SingletonMonoBehaviourFast<SoundManager>{ | |
CriAtomSource source; | |
// Use this for initialization | |
void Start () { | |
StartCoroutine("PlayBGM"); | |
SceneManager.sceneLoaded += OnSceneLoaded; | |
} | |
void OnStart() { | |
} | |
//void OnLevelWasLoaded(int level) { | |
void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode) { | |
//Debug.Log("OnLevelWasLoaded " + level); | |
StartCoroutine("PlayBGM"); | |
} | |
/// <summary> | |
/// シーンに合わせてBGMを変更する | |
/// </summary> | |
/// <returns>The background.</returns> | |
IEnumerator PlayBGM() | |
{ | |
yield return new WaitForSeconds(1.0f); | |
if (SoundManager.instance.source == null) | |
{ | |
SoundManager.instance.source = this.gameObject.AddComponent<CriAtomSource>(); | |
} | |
if(SceneManager.GetSceneByName("Title").isLoaded) | |
{ | |
SoundManager.instance.source.player.SetSelectorLabel("BGM","Title"); | |
SoundManager.instance.source.player.UpdateAll(); | |
SoundManager.instance.source.Play("BGM"); | |
} | |
else if(SceneManager.GetSceneByName("CharaAndStageSelect").isLoaded) | |
{ | |
SoundManager.instance.source.player.SetSelectorLabel("BGM","Game"); | |
SoundManager.instance.source.player.UpdateAll(); | |
SoundManager.instance.source.Play("BGM"); | |
} | |
else if(SceneManager.GetSceneByName("Stage1").isLoaded) | |
{ | |
SoundManager.instance.source.player.SetSelectorLabel("BGM","Stage1"); | |
SoundManager.instance.source.player.UpdateAll(); | |
SoundManager.instance.source.Play("BGM"); | |
} | |
else if(SceneManager.GetSceneByName("Stage2").isLoaded) | |
{ | |
SoundManager.instance.source.player.SetSelectorLabel("BGM","Stage2"); | |
SoundManager.instance.source.player.UpdateAll(); | |
SoundManager.instance.source.Play("BGM"); | |
} | |
else if(SceneManager.GetSceneByName("Stage3").isLoaded) | |
{ | |
SoundManager.instance.source.player.SetSelectorLabel("BGM","Stage3"); | |
SoundManager.instance.source.player.UpdateAll(); | |
SoundManager.instance.source.Play("BGM"); | |
} | |
else if(SceneManager.GetSceneByName("Stage4").isLoaded) | |
{ | |
SoundManager.instance.source.player.SetSelectorLabel("BGM","Stage4"); | |
SoundManager.instance.source.player.UpdateAll(); | |
SoundManager.instance.source.Play("BGM"); | |
} | |
else if(SceneManager.GetSceneByName("Stage5").isLoaded) | |
{ | |
SoundManager.instance.source.player.SetSelectorLabel("BGM","Stage5"); | |
SoundManager.instance.source.player.UpdateAll(); | |
SoundManager.instance.source.Play("BGM"); | |
} | |
} | |
/// <summary> | |
/// SEを鳴らす | |
/// </summary> | |
/// <param name="name">Name.</param> | |
public void PlaySE(string name) | |
{ | |
SoundManager.instance.source.Play(name); | |
} | |
/// <summary> | |
/// 足音 単発 足跡が着くときの音 | |
/// </summary> | |
public void PlayFootStep() | |
{ | |
SoundManager.instance.source.Play("footStep"); | |
} | |
/// <summary> | |
/// 足をすべらせて落ちる音 | |
/// </summary> | |
public void PlayFall() | |
{ | |
SoundManager.instance.source.Play("fall"); | |
} | |
/// <summary> | |
/// 時間切れの音 | |
/// </summary> | |
public void PlayTimeOut() | |
{ | |
SoundManager.instance.source.Play("TimeOut"); | |
} | |
/// <summary> | |
/// ゴールにたどり着いた音 | |
/// </summary> | |
public void PlayGaol() | |
{ | |
SoundManager.instance.source.Play("footSteps"); | |
} | |
/// <summary> | |
/// ワープした時の音 | |
/// </summary> | |
public void PlayWarp() | |
{ | |
SoundManager.instance.source.Play("Warp"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment