public void BmsLoad(string musicName) { setVariables(); bmsFileName = musicName + ".bms"; //string[] lineData = File.ReadAllLines(pathForFiles("axion.bms")); W = 40; bms = gameObject.AddComponent <Bms>(); TextAsset dddata = (TextAsset)Resources.Load("BMS/" + musicName, typeof(TextAsset)); StringReader sr = new StringReader(dddata.text); string line = sr.ReadLine(); while (line != null) { //Debug.Log(line); if (line.StartsWith("#")) { string[] data = line.Split(' '); // exception if (data[0].IndexOf(":") == -1 && data.Length == 1) { continue; } // header field if (data[0].Equals("#TITLE")) { bms.setTitle(data[1]); } else if (data[0].Equals("#ARTIST")) { bms.setArtist(data[1]); } else if (data[0].Equals("#BPM")) { bms.setBpm(double.Parse(data[1])); noteSpeed = W / (4.0f / (float)bms.getBpm() * 60); } else if (data[0].Equals("#PLAYER")) { } else if (data[0].Equals("#GENRE")) { } else if (data[0].Equals("#PLAYLEVEL")) { } else if (data[0].Equals("#RANK")) { } else if (data[0].Equals("#TOTAL")) { } else if (data[0].Equals("#VOLWAV")) { } else if (data[0].Equals("#MIDIFILE")) { } else if (data[0].Equals("#WAV01")) { }// else if (data[0].Equals("#WAV02")) { }// else if (data[0].Equals("#BMP01")) { }// else if (data[0].Equals("#STAGEFILE")) { } else if (data[0].Equals("#VIDEOFILE")) { } else if (data[0].Equals("#BGA")) { } else if (data[0].Equals("#STOP")) { } else if (data[0].Equals("#LNTYPE")) { bms.setLnType(int.Parse(data[1])); } else if (data[0].Equals("#LNOBJ")) { } else if (data[0].Contains("#WAV")) { } else { // data field int bar = 0; // node key Int32.TryParse(data[0].Substring(1, 3), out bar); int channel = 0; // node channel Int32.TryParse(data[0].Substring(4, 2), out channel); string noteStr = data[0].Substring(7); List <int> noteData = getNoteDataOfStr(noteStr); Note note = gameObject.AddComponent <Note>(); note.setBar(bar); note.setChannel(channel); note.setNoteData(noteData); //note.debug(); bms.addNote(note); isFinishLoad = true; } } line = line = sr.ReadLine(); } //string[] lineData = File.ReadAllLines(pathForFiles(bmsFileName)); //foreach (string line in lineData) //{ // //Debug.Log(line); // if (line.StartsWith("#")) // { // string[] data = line.Split(' '); // // exception // if (data[0].IndexOf(":") == -1 && data.Length == 1) // { // continue; // } // // header field // if (data[0].Equals("#TITLE")) // { // bms.setTitle(data[1]); // } // else if (data[0].Equals("#ARTIST")) // { // bms.setArtist(data[1]); // } // else if (data[0].Equals("#BPM")) // { // bms.setBpm(double.Parse(data[1])); // noteSpeed = W / (4.0f / (float)bms.getBpm() * 60); // } // else if (data[0].Equals("#PLAYER")) // { // } // else if (data[0].Equals("#GENRE")) // { // } // else if (data[0].Equals("#PLAYLEVEL")) // { // } // else if (data[0].Equals("#RANK")) // { // } // else if (data[0].Equals("#TOTAL")) // { // } // else if (data[0].Equals("#VOLWAV")) // { // } // else if (data[0].Equals("#MIDIFILE")) // { // } // else if (data[0].Equals("#WAV01")) // { // }// // else if (data[0].Equals("#WAV02")) // { // }// // else if (data[0].Equals("#BMP01")) // { // }// // else if (data[0].Equals("#STAGEFILE")) // { // } // else if (data[0].Equals("#VIDEOFILE")) // { // } // else if (data[0].Equals("#BGA")) // { // } // else if (data[0].Equals("#STOP")) // { // } // else if (data[0].Equals("#LNTYPE")) // { // bms.setLnType(int.Parse(data[1])); // } // else if (data[0].Equals("#LNOBJ")) // { // } // else if (data[0].Contains("#WAV")) // { // } // else // { // // data field // int bar = 0; // node key // Int32.TryParse(data[0].Substring(1, 3), out bar); // int channel = 0; // node channel // Int32.TryParse(data[0].Substring(4, 2), out channel); // string noteStr = data[0].Substring(7); // List<int> noteData = getNoteDataOfStr(noteStr); // Note note = gameObject.AddComponent<Note>(); // note.setBar(bar); // note.setChannel(channel); // note.setNoteData(noteData); // //note.debug(); // bms.addNote(note); // isFinishLoad = true; // } // } //} if (isFinishLoad) { float musicStartTimeBias = 0; float time_delay = 3.0f; if (gameManager == null) { gameManager = FindObjectOfType <GameManager>(); } float bias = gameManager.getMusicBias(musicName); float biasByTimeDelay = time_delay * noteSpeed; foreach (Note note in bms.getNoteList()) { int noteNum = note.noteData.Count; int cnt = 0; foreach (int i in note.noteData) { if (i == 1) { switch (note.channel) { case 11: GameObject r1 = Instantiate(Note135); r1.transform.localPosition = new Vector3(-10, -15, biasByTimeDelay + bias + (note.bar * W) + (W / noteNum * cnt)); objectList.Add(r1); break; case 12: GameObject r2 = Instantiate(Note24); r2.transform.localPosition = new Vector3(-5, -15, biasByTimeDelay + bias + (note.bar * W) + (W / noteNum * cnt)); objectList.Add(r2); break; case 13: GameObject r3 = Instantiate(Note135); r3.transform.localPosition = new Vector3(0, -15, biasByTimeDelay + bias + (note.bar * W) + (W / noteNum * cnt)); objectList.Add(r3); break; case 14: GameObject r4 = Instantiate(Note24); r4.transform.localPosition = new Vector3(5, -15, biasByTimeDelay + bias + (note.bar * W) + (W / noteNum * cnt)); objectList.Add(r4); break; case 15: GameObject r5 = Instantiate(Note135); r5.transform.localPosition = new Vector3(10, -15, biasByTimeDelay + bias + (note.bar * W) + (W / noteNum * cnt)); objectList.Add(r5); break; } } else if (i == 2) { float musicStartBias = (note.bar * W) + (W / noteNum * cnt); musicStartTimeBias = musicStartBias / noteSpeed; } cnt++; } } theAudio.playBGMWithDelay(musicName, musicStartTimeBias + time_delay); } }
private void BmsLoad() { bms = gameObject.AddComponent <Bms>(); string[] lineData = System.IO.File.ReadAllLines("Assets/BmsFiles/BS_5a.bms"); //File.ReadAllLines(Application.dataPath + "/BmsFiles/" + bmsFileName); foreach (string line in lineData) { if (line.StartsWith("#")) { string[] data = line.Split(' '); // 데이터 섹션이 아니면서 헤더 데이터가 없는 경우에는 건너 뜀. if (data[0].IndexOf(":") == -1 && data.Length == 1) { continue; } // 헤더 섹션 if (data[0].Equals("#TITLE")) { bms.setTitle(data[1]); } else if (data[0].Equals("#ARTIST")) { bms.setArtist(data[1]); } else if (data[0].Equals("#BPM")) { bms.setBpm(double.Parse(data[1])); } else if (data[0].Equals("#PLAYER")) { } else if (data[0].Equals("#GENRE")) { } else if (data[0].Equals("#PLAYLEVEL")) { } else if (data[0].Equals("#RANK")) { } else if (data[0].Equals("#TOTAL")) { } else if (data[0].Equals("#VOLWAV")) { } else if (data[0].Equals("#MIDIFILE")) { } else if (data[0].Equals("#WAV")) { } else if (data[0].Equals("#BMP")) { } else if (data[0].Equals("#STAGEFILE")) { } else if (data[0].Equals("#VIDEOFILE")) { } else if (data[0].Equals("#BGA")) { } else if (data[0].Equals("#STOP")) { } else if (data[0].Equals("#LNTYPE")) { bms.setLnType(int.Parse(data[1])); } else if (data[0].Equals("#LNOBJ")) { } else { // 위의 경우에 모두 해당하지 않을 경우, 데이터 섹션 int bar = 0; Int32.TryParse(data[0].Substring(1, 3), out bar); int channel = 0; Int32.TryParse(data[0].Substring(4, 2), out channel); string noteStr = data[0].Substring(7); List <int> noteData = getNoteDataOfStr(noteStr); Note note = gameObject.AddComponent <Note>(); note.setBar(bar); note.setChannel(channel); note.setNoteData(noteData); // note.debug(); bms.addNote(note); } } } if (bms.getNoteList().Count != 0) { isFinishLoad = true; } }
private void BmsLoad() { //bmsFileName = "MINO - anacne.bms"; W = 40; bms = gameObject.AddComponent <Bms>(); string[] lineData = File.ReadAllLines(pathForFiles(bmsFileName)); foreach (string line in lineData) { //Debug.Log(line); if (line.StartsWith("#")) { string[] data = line.Split(' '); // exception if (data[0].IndexOf(":") == -1 && data.Length == 1) { continue; } // header field if (data[0].Equals("#TITLE")) { bms.setTitle(data[1]); } else if (data[0].Equals("#ARTIST")) { bms.setArtist(data[1]); } else if (data[0].Equals("#BPM")) { bms.setBpm(double.Parse(data[1])); } else if (data[0].Equals("#PLAYER")) { } else if (data[0].Equals("#GENRE")) { } else if (data[0].Equals("#PLAYLEVEL")) { } else if (data[0].Equals("#RANK")) { } else if (data[0].Equals("#TOTAL")) { } else if (data[0].Equals("#VOLWAV")) { } else if (data[0].Equals("#MIDIFILE")) { } else if (data[0].Equals("#WAV02")) { }// else if (data[0].Equals("#BMP01")) { }// else if (data[0].Equals("#STAGEFILE")) { } else if (data[0].Equals("#VIDEOFILE")) { } else if (data[0].Equals("#BGA")) { } else if (data[0].Equals("#STOP")) { } else if (data[0].Equals("#LNTYPE")) { bms.setLnType(int.Parse(data[1])); } else if (data[0].Equals("#LNOBJ")) { } else { // data field int bar = 0; // node key Int32.TryParse(data[0].Substring(1, 3), out bar); int channel = 0; // node channel Int32.TryParse(data[0].Substring(4, 2), out channel); string noteStr = data[0].Substring(7); List <int> noteData = getNoteDataOfStr(noteStr); Note note = gameObject.AddComponent <Note>(); note.setBar(bar); note.setChannel(channel); note.setNoteData(noteData); //note.debug(); bms.addNote(note); isFinishLoad = true; } } } if (isFinishLoad) { foreach (Note note in bms.getNoteList()) { switch (note.channel) { case 11: int cnt = 0; switch (note.noteData.Count) { case 1: GameObject r_1 = Instantiate(Note135); r_1.transform.position = new Vector3(-10, -15, 30 + note.bar * W); objectList.Add(r_1); break; case 2: foreach (int i in note.noteData) { if (i == 1) { GameObject r_2 = Instantiate(Note135); r_2.transform.position = new Vector3(-10, -15, 30 + (note.bar * W) + (W / 8 * cnt)); objectList.Add(r_2); } cnt += 4; } break; case 4: foreach (int i in note.noteData) { if (i == 1) { GameObject r_4 = Instantiate(Note135); r_4.transform.position = new Vector3(-10, -15, 30 + (note.bar * W) + (W / 8 * cnt)); objectList.Add(r_4); } cnt += 2; } break; case 8: foreach (int i in note.noteData) { if (i == 1) { GameObject r_8 = Instantiate(Note135); r_8.transform.position = new Vector3(-10, -15, 30 + (note.bar * W) + (W / 8 * cnt)); objectList.Add(r_8); } cnt += 1; } break; } break; case 12: int cnt2 = 0; switch (note.noteData.Count) { case 1: GameObject g_1 = Instantiate(Note24); g_1.transform.position = new Vector3(-5, -15, 30 + note.bar * W); objectList.Add(g_1); break; case 2: foreach (int i in note.noteData) { if (i == 1) { GameObject g_2 = Instantiate(Note24); g_2.transform.position = new Vector3(-5, -15, 30 + (note.bar * W) + (W / 8 * cnt2)); objectList.Add(g_2); } cnt2 += 4; } break; case 4: foreach (int i in note.noteData) { if (i == 1) { GameObject g_4 = Instantiate(Note24); g_4.transform.position = new Vector3(-5, -15, 30 + (note.bar * W) + (W / 8 * cnt2)); objectList.Add(g_4); } cnt2 += 2; } break; case 8: foreach (int i in note.noteData) { if (i == 1) { GameObject g_8 = Instantiate(Note24); g_8.transform.position = new Vector3(-5, -15, 30 + (note.bar * W) + (W / 8 * cnt2)); objectList.Add(g_8); } cnt2 += 1; } break; } break; case 13: int cnt3 = 0; switch (note.noteData.Count) { case 1: GameObject g_1 = Instantiate(Note135); g_1.transform.position = new Vector3(0, -15, 30 + note.bar * W); objectList.Add(g_1); break; case 2: foreach (int i in note.noteData) { if (i == 1) { GameObject g_2 = Instantiate(Note135); g_2.transform.position = new Vector3(0, -15, 30 + (note.bar * W) + (W / 8 * cnt3)); objectList.Add(g_2); } cnt3 += 4; } break; case 4: foreach (int i in note.noteData) { if (i == 1) { GameObject g_4 = Instantiate(Note135); g_4.transform.position = new Vector3(0, -15, 30 + (note.bar * W) + (W / 8 * cnt3)); objectList.Add(g_4); } cnt3 += 2; } break; case 8: foreach (int i in note.noteData) { if (i == 1) { GameObject g_8 = Instantiate(Note135); g_8.transform.position = new Vector3(0, -15, 30 + (note.bar * W) + (W / 8 * cnt3)); objectList.Add(g_8); } cnt3 += 1; } break; } break; case 14: int cnt4 = 0; switch (note.noteData.Count) { case 1: GameObject g_1 = Instantiate(Note24); g_1.transform.position = new Vector3(5, -15, 30 + note.bar * W); objectList.Add(g_1); break; case 2: foreach (int i in note.noteData) { if (i == 1) { GameObject g_2 = Instantiate(Note24); g_2.transform.position = new Vector3(5, -15, 30 + (note.bar * W) + (W / 8 * cnt4)); objectList.Add(g_2); } cnt4 += 4; } break; case 4: foreach (int i in note.noteData) { if (i == 1) { GameObject g_4 = Instantiate(Note24); g_4.transform.position = new Vector3(5, -15, 30 + (note.bar * W) + (W / 8 * cnt4)); objectList.Add(g_4); } cnt4 += 2; } break; case 8: foreach (int i in note.noteData) { if (i == 1) { GameObject g_8 = Instantiate(Note24); g_8.transform.position = new Vector3(5, -15, 30 + (note.bar * W) + (W / 8 * cnt4)); objectList.Add(g_8); } cnt4 += 1; } break; } break; case 15: int cnt5 = 0; switch (note.noteData.Count) { case 1: GameObject g_1 = Instantiate(Note135); g_1.transform.position = new Vector3(10, -15, 30 + note.bar * W); objectList.Add(g_1); break; case 2: foreach (int i in note.noteData) { if (i == 1) { GameObject g_2 = Instantiate(Note135); g_2.transform.position = new Vector3(10, -15, 30 + (note.bar * W) + (W / 8 * cnt5)); objectList.Add(g_2); } cnt5 += 4; } break; case 4: foreach (int i in note.noteData) { if (i == 1) { GameObject g_4 = Instantiate(Note135); g_4.transform.position = new Vector3(10, -15, 30 + (note.bar * W) + (W / 8 * cnt5)); objectList.Add(g_4); } cnt5 += 2; } break; case 8: foreach (int i in note.noteData) { if (i == 1) { GameObject g_8 = Instantiate(Note135); g_8.transform.position = new Vector3(10, -15, 30 + (note.bar * W) + (W / 8 * cnt5)); objectList.Add(g_8); } cnt5 += 1; } break; } break; } } } }