Created
November 2, 2017 18:41
-
-
Save tatmos/b52a95506d15bcbfa7219a48e28d8adb to your computer and use it in GitHub Desktop.
GGJ2015軽井沢会場での作品「Yuden」( https://www.youtube.com/watch?v=_Uj3EREiBnQ&feature=youtu.be ) のSoundManager。UnityオーディオでSE BGMなど。
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 System.Collections.Generic; | |
public class SoundManager : MonoBehaviour { | |
public static SoundManager main = null; | |
AudioSource audioSourceBGM; | |
List<AudioSource> audioSourceSE = new List<AudioSource>(); | |
public List<AudioClip> seClipList = new List<AudioClip>(); | |
public List<AudioClip> bgmClipList = new List<AudioClip>(); | |
public List<AudioClip> seClipFootStepList = new List<AudioClip>(); | |
void Awake() | |
{ | |
if(main != null) | |
{ | |
GameObject.Destroy(this.gameObject); | |
} else | |
{ | |
main = this; | |
} | |
audioSourceBGM = this.gameObject.AddComponent<AudioSource>(); | |
for(int i =0;i < 8;i++){ | |
audioSourceSE.Add(this.gameObject.AddComponent<AudioSource>()); | |
} | |
} | |
// Use this for initialization | |
void Start () { | |
StartCoroutine("PlayOcean1"); | |
} | |
private IEnumerator PlayOcean1() { | |
// ログ出力 | |
Debug.Log ("1"); | |
// 1秒待つ | |
yield return new WaitForSeconds (1.0f); | |
// ログ出力 | |
Debug.Log ("2"); | |
SoundManager.main.PlayBGM(0); | |
} | |
int seCount = 0; | |
public void PlaySE(int id) | |
{ | |
audioSourceSE[seCount].clip = seClipList[id]; | |
audioSourceSE[seCount].Play(); | |
seCount++; | |
if(seCount == 8)seCount = 0; | |
} | |
public void PlayBGM(int id) | |
{ | |
audioSourceBGM.clip = bgmClipList[id]; | |
audioSourceBGM.volume = 0.4f; | |
audioSourceBGM.loop = true; | |
audioSourceBGM.Play(); | |
} | |
public bool debugFlag = false; | |
void OnGUI() | |
{ | |
if(debugFlag){ | |
if(GUILayout.Button("SE0")){ | |
SoundManager.main.PlaySE(0); | |
} | |
if(GUILayout.Button("SE1")){ | |
SoundManager.main.PlaySE(1); | |
} | |
if(GUILayout.Button("SE2")){ | |
SoundManager.main.PlaySE(2); | |
} | |
if(GUILayout.Button("SEOcean")){ | |
SoundManager.main.PlaySE(10); | |
} | |
} | |
} | |
//---------- | |
int footStepCount = 0; | |
public void PlayFootSteps(int id) | |
{ | |
audioSourceSE[seCount].clip = seClipFootStepList[id]; | |
audioSourceSE[seCount].Play(); | |
seCount += 1; | |
if (seCount > 7) | |
{ | |
seCount = 0; | |
} | |
//footStepCount++; | |
} | |
public void PlayOcean() | |
{ | |
SoundManager.main.PlayBGM(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment