Created
November 2, 2017 18:08
-
-
Save tatmos/8c2aa9e281040dac668cdf9e29ea3987 to your computer and use it in GitHub Desktop.
2016GGJの絶対音感乙女サモナー( https://www.youtube.com/watch?v=HHPGS_zO-qs&feature=youtu.be )のSoundManager。ADX2LE、MusicEngine、自前FM音源など制御。カテゴリボリュームとかセレクタラベルの設定もしてる。
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; | |
public class SoundManager : MonoBehaviour | |
{ | |
public static FmInstrument fmInstrument = null; | |
public CriAtomSource atomSource; | |
public CriAtomExPlayer atomPlayer; | |
public CriAtomExPlayer atomTitlePlayer; | |
public CriAtomExPlayer atomTitleVoicePlayer; | |
public static SoundManager main = null; | |
void Awake() | |
{ | |
if (main == null)// || Application.loadedLevelName == "TitleScene"){ | |
{ | |
if (main != null) | |
{ | |
GameObject.Destroy(main.gameObject); // 本当はゲームオブジェクトを消したいあEventSystemがあるのでけせない(消すとボタンとか動かなくなる) | |
// GameObject.Destroy(main); // sound managerだけでも削除 | |
} | |
main = this; | |
GameObject.DontDestroyOnLoad(this.gameObject); | |
} else | |
{ | |
GameObject.Destroy(this.gameObject); | |
return; | |
} | |
} | |
// Use this for initialization | |
void Start() | |
{ | |
atomSource = GetComponent<CriAtomSource>(); | |
if (fmInstrument == null) | |
{ | |
GameObject go = this.gameObject.transform.FindChild("FmInstrument").gameObject; | |
fmInstrument = go.GetComponent<FmInstrument>(); | |
} | |
if(atomPlayer == null){ | |
atomPlayer = new CriAtomExPlayer(); | |
atomTitlePlayer = new CriAtomExPlayer(); | |
atomTitleVoicePlayer = new CriAtomExPlayer(); | |
} | |
// if (atomTitleVoicePlayer != null) | |
// { | |
// atomTitleVoicePlayer.SetCue(null, "titleTubuyaki"); | |
// atomTitleVoicePlayer.Start(); | |
// } | |
} | |
void OnDestroy() | |
{ | |
if (atomPlayer != null) | |
{ | |
atomPlayer.Dispose(); // 破棄 | |
atomPlayer = null; | |
atomTitlePlayer.Dispose(); | |
atomTitlePlayer = null; | |
atomTitleVoicePlayer.Dispose(); | |
atomTitleVoicePlayer = null; | |
} | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
public static void OnPlay(int soundId = 1) | |
{ | |
soundId = Random.Range(0, 2); | |
// ADX2LEを鳴らす | |
Music.QuantizePlay(SoundManager.main.atomSource); | |
if (soundId == 0) | |
{ | |
} else | |
{ | |
// FM Synthを鳴らす | |
if (fmInstrument.useFm) | |
{ | |
FmAudioManager fma = fmInstrument.fmAudioManager [Random.Range(0, 8)]; | |
fma.RnadomPreset(); | |
Music.QuantizePlay(fma); | |
} | |
} | |
} | |
public void BgmVolume(float vol) | |
{ | |
if (SoundManager.main != null && SoundManager.main.atomTitlePlayer != null) | |
{ | |
//SoundManager.main.atomTitlePlayer.Stop(); | |
//SoundManager.main.atomTitlePlayer.SetCue(null, "title"); | |
{ | |
CriAtom.SetCategoryVolume("BGM", vol); | |
} | |
//SoundManager.main.atomTitlePlayer.Start(); | |
} | |
} | |
public void SeVolume(float vol) | |
{ | |
if (SoundManager.main != null && SoundManager.main.atomPlayer != null) | |
{ | |
CriAtom.SetCategoryVolume("SE", vol); | |
SoundManager.main.atomPlayer.Stop(); | |
SoundManager.main.atomPlayer.SetCue(null, "bell"); | |
SoundManager.main.atomPlayer.Start(); | |
} | |
} | |
public void OnGotoCollectionMode() | |
{ | |
Music.SetNextBlock("collection"); // 曲ブロックを次へ進行 | |
} | |
public void OnPlayStart() | |
{ | |
if (SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "start"); | |
SoundManager.main.atomPlayer.Start(); | |
Music.SetNextBlock("intro"); // 曲ブロックを次へ進行 | |
} | |
// if (atomTitleVoicePlayer != null) | |
// { | |
// atomTitleVoicePlayer.Stop(); | |
// } | |
} | |
public void OnPlayButton(int buttonId) | |
{ | |
if (SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "button" + buttonId); | |
SoundManager.main.atomPlayer.Start(); | |
} | |
} | |
/// <summary> | |
/// 魔法陣にキャラを設置開始の音(hyui) | |
/// </summary> | |
public static void OnMahoujinCharaDragStart() | |
{ | |
if (SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "hyui"); | |
SoundManager.main.atomPlayer.Start(); | |
} | |
} | |
/// <summary> | |
// 魔法陣にキャラを設置しようとしているときの角度でクリックした時の音(kachi) | |
/// </summary> | |
public static void OnMahoujinCharaDragging() | |
{ | |
if (SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "kachi"); | |
SoundManager.main.atomPlayer.Start(); | |
} | |
} | |
/// <summary> | |
/// 魔法陣にキャラを設置した時音(kasha) | |
/// </summary> | |
public static void OnMahoujinCharaDragEnd() | |
{ | |
if (SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "kasha"); | |
SoundManager.main.atomPlayer.Start(); | |
SoundManager.main.atomPlayer.SetCue(null, "dooya"); | |
SoundManager.main.atomPlayer.Start(); | |
} | |
} | |
/// <summary> | |
/// 魔法陣完成音 | |
/// </summary> | |
public static void OnMahoujinBuildEnd() | |
{ | |
if (SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "button2"); | |
SoundManager.main.atomPlayer.Start(); | |
Music.SetNextBlock("loop2"); // 曲ブロックを次へ進行 | |
} | |
} | |
// ーーーーーー | |
/// <summary> | |
/// 魔法陣演奏終了時 | |
/// </summary> | |
public static void OnMahoujinPlayEnd() | |
{ | |
if (SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "button2"); | |
SoundManager.main.atomPlayer.Start(); | |
} | |
} | |
/// <summary> | |
/// リザルト終了時 | |
/// </summary> | |
public static void OnResultEnd() | |
{ | |
if (SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "button4"); | |
SoundManager.main.atomPlayer.Start(); | |
Music.SetNextBlock("result_end"); // リザルトへ曲を進行 | |
} | |
} | |
public static void OnCollectionEnd() | |
{ | |
if (SoundManager.main !=null && SoundManager.main.atomPlayer != null) | |
{ | |
SoundManager.main.atomPlayer.SetCue(null, "button4"); | |
SoundManager.main.atomPlayer.Start(); | |
Music.SetNextBlock("title"); // titleへ曲を進行 | |
} | |
} | |
//--------- | |
/// <summary> | |
/// サモンパラメータが増加する時の音 | |
/// </summary> | |
public static void OnPlayAddSummonParam(CharacterElement summonParamType) | |
{ | |
// 属性によってセレクタラベル変更 | |
switch (summonParamType) | |
{ | |
case CharacterElement.Dark: | |
SoundManager.main.atomSource.player.SetSelectorLabel("Element","dark"); | |
break; | |
case CharacterElement.Light: | |
SoundManager.main.atomSource.player.SetSelectorLabel("Element","light"); | |
break; | |
case CharacterElement.Water: | |
SoundManager.main.atomSource.player.SetSelectorLabel("Element","water"); | |
break; | |
case CharacterElement.Fire: | |
SoundManager.main.atomSource.player.SetSelectorLabel("Element","fire"); | |
break; | |
case CharacterElement.Wood: | |
SoundManager.main.atomSource.player.SetSelectorLabel("Element","wood"); | |
break; | |
} | |
// ADX2LEを鳴らす | |
Music.QuantizePlay(SoundManager.main.atomSource); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment