Advertisement
libdo

Untitled

Nov 5th, 2017
7,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class SoundManager : MonoBehaviour {
  6.  
  7. public static SoundManager main = null;
  8.  
  9. AudioSource audioSourceBGM;
  10. public List<AudioClip> bgmClipList = new List<AudioClip>();
  11.  
  12. public enum TrgType {
  13. CLOSE,
  14. SWITCH_ENEMY,
  15. OPEN,
  16. }
  17.  
  18. public class BPM_Time_Struct
  19. {
  20. public BPM_Time_Struct(TrgType type, float t,float b,string n)
  21. {
  22. trgtype = type;
  23. changeTime = t;
  24. bpm = b;
  25. name=n;
  26. }
  27.  
  28. public TrgType trgtype = TrgType.CLOSE;
  29. public float changeTime = 0;
  30. public float bpm = 105;
  31. public string name = "";
  32. }
  33.  
  34. void Awake()
  35. {
  36. if(main != null)
  37. {
  38. GameObject.Destroy(this);
  39. } else
  40. {
  41. main = this;
  42. }
  43. }
  44.  
  45. public List<BPM_Time_Struct> bpmList = new List<BPM_Time_Struct>();
  46.  
  47. ParticleSystem ps;
  48.  
  49. [SerializeField]
  50. private int _RenderQueue = 4000;
  51.  
  52. void RenderStart ()
  53. {
  54. renderer.material.renderQueue = _RenderQueue;
  55.  
  56. Transform trans = transform;
  57. for (int i = 0; i < trans.childCount; i++) {
  58. trans.GetChild (i).gameObject.renderer.material.renderQueue = _RenderQueue;
  59. }
  60.  
  61. ps = this.gameObject.GetComponent<ParticleSystem>();
  62. }
  63.  
  64. // Use this for initialization
  65. void Start () {
  66. RenderStart();
  67.  
  68. bpmList.Add(new BPM_Time_Struct( TrgType.SWITCH_ENEMY, 0,105,"A"));
  69. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, (9.03f/8)*1,105,"A"));
  70. bpmList.Add(new BPM_Time_Struct( TrgType.CLOSE, (9.03f/8)*2,105,"A"));
  71. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, (9.03f/8)*3,105,"A"));
  72. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, (9.03f/8)*4,105,"A"));
  73. bpmList.Add(new BPM_Time_Struct( TrgType.CLOSE, (9.03f/8)*5,105,"A"));
  74. bpmList.Add(new BPM_Time_Struct( TrgType.SWITCH_ENEMY, (9.03f/8)*6,105,"A"));
  75. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 9.03f + ((17.66f-9.03f)/8)*0,118,"B"));
  76. bpmList.Add(new BPM_Time_Struct( TrgType.CLOSE, 9.03f + ((17.66f-9.03f)/8)*1,118,"B"));
  77. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 9.03f + ((17.66f-9.03f)/8)*2,118,"B"));
  78. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 9.03f + ((17.66f-9.03f)/8)*3,118,"B"));
  79. bpmList.Add(new BPM_Time_Struct( TrgType.CLOSE, 9.03f + ((17.66f-9.03f)/8)*4,118,"B"));
  80. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 9.03f + ((17.66f-9.03f)/8)*5,118,"B"));
  81. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 9.03f + ((17.66f-9.03f)/8)*6,118,"B"));
  82. bpmList.Add(new BPM_Time_Struct( TrgType.CLOSE, 9.03f + ((17.66f-9.03f)/8)*7,118,"B"));
  83. bpmList.Add(new BPM_Time_Struct( TrgType.SWITCH_ENEMY, 17.66f + ((29.22f-17.66f)/8)*0,152,"C"));
  84. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 17.66f + ((29.22f-17.66f)/8)*1,152,"C"));
  85. bpmList.Add(new BPM_Time_Struct( TrgType.CLOSE, 17.66f + ((29.22f-17.66f)/8)*2,152,"C"));
  86. bpmList.Add(new BPM_Time_Struct( TrgType.SWITCH_ENEMY, 17.66f + ((29.22f-17.66f)/8)*3,152,"C"));
  87. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 17.66f + ((29.22f-17.66f)/8)*4,152,"C"));
  88. bpmList.Add(new BPM_Time_Struct( TrgType.CLOSE, 17.66f + ((29.22f-17.66f)/8)*5,152,"C"));
  89. bpmList.Add(new BPM_Time_Struct( TrgType.SWITCH_ENEMY, 17.66f + ((29.22f-17.66f)/8)*6,152,"C"));
  90. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 17.66f + ((29.22f-17.66f)/8)*7,152,"C"));
  91. bpmList.Add(new BPM_Time_Struct( TrgType.OPEN, 29.22f+2f,152,"EndPre"));
  92. bpmList.Add(new BPM_Time_Struct( TrgType.CLOSE, 29.22f+4f,152,"End"));
  93.  
  94. EventPartChange += PartChangeTest;
  95.  
  96. audioSourceBGM = this.gameObject.AddComponent<AudioSource>();
  97.  
  98. if(Application.loadedLevelName == "game"){
  99. audioSourceBGM.clip = bgmClipList[Random.Range(0,7)%(bgmClipList.Count-1)];
  100. audioSourceBGM.Play();
  101. }
  102. }
  103.  
  104.  
  105. void PartChangeTest(BPM_Time_Struct arg)
  106. {
  107. Debug.Log(arg.trgtype.ToString());
  108. }
  109.  
  110.  
  111.  
  112. // int lastBeatNo = 0;
  113. // int beatNo = 0;
  114.  
  115. BPM_Time_Struct GetBPM_Time_Struct(float time)
  116. {
  117. if(time == 0)
  118. {
  119. return bpmList[0];
  120. }
  121.  
  122. for(int btsIndex = 0;btsIndex < bpmList.Count - 1;btsIndex++)
  123. {
  124. if(bpmList[btsIndex].changeTime < time && time < bpmList[btsIndex+1].changeTime)
  125. {
  126. return bpmList[btsIndex];
  127. }
  128. }
  129.  
  130. return bpmList[bpmList.Count-1];
  131. }
  132.  
  133.  
  134. BPM_Time_Struct lastBPM_Time_Struct;
  135. public BPM_Time_Struct currentBPM_Time_Struct;
  136.  
  137. // Update is called once per frame
  138. void Update () {
  139. if(audioSourceBGM.isPlaying)
  140. {
  141. currentBPM_Time_Struct = GetBPM_Time_Struct(audioSourceBGM.time);
  142.  
  143. if(currentBPM_Time_Struct != lastBPM_Time_Struct)
  144. {
  145. EventPartChange(currentBPM_Time_Struct);
  146. lastBPM_Time_Struct = currentBPM_Time_Struct;
  147. }
  148. }
  149. }
  150.  
  151. //---------------イベント-------------------------------------------------------------------------
  152. public delegate void PartChange (BPM_Time_Struct arg); // ビートイベントコールバック登録用デリゲート
  153. static public PartChange EventPartChange; // ビートイベントコールバック登録用
  154.  
  155. //----------------------------------------------------------------------------------
  156.  
  157.  
  158. public List<AudioClip> continueClipList = new List<AudioClip>();
  159. public void PlayneCount(int neCount)
  160. {
  161. if(neCount%20 == 0){
  162. //Debug.Log("neCount " + neCount);
  163. audio.PlayOneShot(continueClipList[(neCount/20)%(continueClipList.Count-1)],0.41f);
  164. }
  165. }
  166.  
  167.  
  168. public List<AudioClip> hajikuClipList = new List<AudioClip>();
  169.  
  170. int HajikuCount = 0;
  171. public void PlayHajiku()
  172. {
  173.  
  174. HajikuCount++;
  175. if(HajikuCount%4 == 0){
  176. audio.PlayOneShot(hajikuClipList[0],0.7f);
  177.  
  178. ps.enableEmission = true;
  179. ps.maxParticles = 100;
  180. }
  181. }
  182.  
  183. public void PlayShut()
  184. {
  185. ps.maxParticles = 0;
  186. ps.enableEmission = false;
  187. {
  188. audio.PlayOneShot(hajikuClipList[1],0.7f);
  189. }
  190. }
  191.  
  192. public void PlayClose()
  193. {
  194. ps.maxParticles = 0;
  195. ps.enableEmission = false;
  196. {
  197. audio.PlayOneShot(hajikuClipList[2],0.7f);
  198. }
  199. }
  200.  
  201. int GrowlCount = 0;
  202. public void PlayGrowl()
  203. {
  204. GrowlCount += Random.Range(1,3);
  205. ps.maxParticles = 0;
  206. ps.enableEmission = false;
  207. if(GrowlCount%8 == 0)
  208. {
  209. audio.PlayOneShot(hajikuClipList[3],0.7f);
  210. }
  211. }
  212.  
  213. public List<AudioClip> titleClipList = new List<AudioClip>();
  214. public void PlayTitle()
  215. {
  216. //audio.PlayOneShot(titleClipList[0],0.7f);
  217.  
  218. audioSourceBGM.clip = titleClipList[0];
  219. audioSourceBGM.loop = true;
  220. audioSourceBGM.Play();
  221. }
  222.  
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement