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