void Parse() { Debug.Log("Parsing"); DirectoryInfo info = new DirectoryInfo(Game_Data.songDirectory); FileInfo[] smFiles = info.GetFiles("*.sm", SearchOption.AllDirectories); Debug.Log("Parsing Dir: " + Game_Data.songDirectory + " | Amount: " + smFiles.Length); for (int i = 0; i < smFiles.Length; i++) { Song_Parser parser = new Song_Parser(); Debug.Log("Parsing File: " + smFiles[i].FullName); Song_Parser.Metadata songData = parser.Parse(smFiles[i].FullName); audioStartTime = songData.sampleStart; audioLength = songData.sampleLength; if (!songData.valid) { //Song data is not valid Debug.Log("Song data is not valid"); continue; } else { GameObject songObj = (GameObject)Instantiate(songSelectionTemplate, songSelectionList.transform.position, Quaternion.identity); songObj.GetComponentInChildren <Text>().text = songData.title + " - " + songData.artist; songObj.transform.parent = songSelectionList.transform; songObj.transform.localScale = new Vector3(1, 1, 1); //Scale changes for some reason - reset it //Get access to the button control Button songBtn = songObj.GetComponentInChildren <Button>(); if (File.Exists(songData.bannerPath)) { Texture2D texture = new Texture2D(275, 52); texture.LoadImage(File.ReadAllBytes(songData.bannerPath)); Debug.Log(songData.bannerPath); songBtn.image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f); songBtn.image.material.SetColor("_Color", Color.white); songObj.GetComponentInChildren <Text>().enabled = false; } songBtn.onClick.AddListener(delegate { StartSong(songData); }); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerEnter; entry.callback.AddListener(eventData => { if (songData.musicPath != currentSongPath) { StartCoroutine(PreviewTrack(songData.musicPath)); } }); songBtn.GetComponent <EventTrigger>().triggers.Add(entry); } } }
// todo: // make it play audio // make it play steps // make it get kb input // Use this for initialization public void Start() { // System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); // System.Windows.Forms.DialogResult result = fbd.ShowDialog(); // Debug.Log(fbd.SelectedPath); // load game directory // Game_Data.songDirectory = "C:\\Users\\Jacqueline Liang\\Desktop\\simfile"; // Game_Data.validSongDir = true; // Debug.Log(Game_Data.songDirectory); // set up audiosource audioSource = GetComponent <AudioSource>(); // Song_Parser.Metadata meta = Parse(); // the simfile Song_Parser parser = new Song_Parser(); // Song_Parser.Metadata meta = parser.Parse("Dir: D:\\ddrvr\\ddrvr\\Assets\\simfile | Amount: 0"); //Song_Parser.Metadata // meta = parser.Parse("D:\\ddrvr\\ddrvr\\Assets\\simfile\\Eros and Apollo\\eros.sm"); var menu = FindObjectOfType <Menufy>(); var path = menu.songPath; audioSource.clip = menu.songClip; DestroyObject(menu); meta = parser.Parse(path); // meta = parser.Parse("D:\\ddrvr\\ddrvr\\Assets\\simfile\\Vinyl\\Vinyl.sm"); //audioSource.PlayDelayed(meta.offset); // can pas a delay an an argument GameObject manager = GameObject.FindGameObjectWithTag("GameManager"); manager.GetComponent <Step_Generator>().InitSteps(meta);//, Game_Data.difficulty); /*int i; * for (i=0;i<meta.challenge.bars.Count;i++) * { * Debug.Log(""+meta.challenge.bars[i][0].up); * }*/ audioSource.Play(); //audioSource.PlayDelayed(300000); StartCoroutine(stopDelay(audioSource.clip.length)); //Song_Parser.NoteData notes = parser.ParseNotes("D:\\ddrvr\\ddrvr\\Assets\\simfile\\Vinyl\\Lone Digger.sm"); // StartCoroutine(LoadTrack(meta.musicPath, meta)); // start the game }
// safe to delete, not called Song_Parser.Metadata Parse() // calls Song_Parser.cs { Debug.Log("Parsing"); // get all simfiles in a FileInfo[] array DirectoryInfo info = new DirectoryInfo(Game_Data.songDirectory); FileInfo[] smFiles = info.GetFiles("*.sm", SearchOption.AllDirectories); Debug.Log("Parsing Dir: " + Game_Data.songDirectory + " | Amount: " + smFiles.Length); Song_Parser parser = new Song_Parser(); Song_Parser.Metadata songData = parser.Parse(Game_Data.songDirectory); return(songData); } // end parse fxn
/// <summary> /// get song data when song is selected /// </summary> void Parse() { DirectoryInfo info = new DirectoryInfo(Game_Data.songDirectory); FileInfo[] smFiles = info.GetFiles("*.sm", SearchOption.AllDirectories); for (int i = 0; i < smFiles.Length; i++) // loop all files { Song_Parser parser = new Song_Parser(); Song_Parser.Metadata songData = parser.Parse(smFiles[i].FullName); audioStartTime = songData.sampleStart; audioLength = songData.sampleLength; if (songData.valid) { //Instantiate(Object original, Vector3 position, Quaternion rotation); // Quaternion.identity - "no rotation" - the object is perfectly aligned with the world or parent axes GameObject songObj = (GameObject)Instantiate(songSelectionTemplate, songSelectionList.transform.position, Quaternion.identity); songObj.GetComponentInChildren <Text>().text = songData.title + " - " + songData.artist; //the text that is inside the new songObj becomes titl - artist (example - Bad Romance - Gaga) songObj.transform.parent = songSelectionList.transform; //the songObj depends on the whole list position songObj.transform.localScale = new Vector3(1, 1, 1); // scale of the transform relative to the parent. //Get access to the button control Button songBtn = songObj.GetComponentInChildren <Button>(); //if there is a bannerPath file inside of the songData object, load the banner instead of the text if (File.Exists(songData.bannerPath)) { Texture2D texture = new Texture2D(275, 52); // 275 width, 52 height, texture.LoadImage(File.ReadAllBytes(songData.bannerPath)); // add banner as texture image // init a sprite that uses the texture, a sharp edged (edge radius - 0) rectangle, a pivot equal to the vector and 100pixels per unit songBtn.image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f); songBtn.image.material.SetColor("_Color", Color.white); //no color tin over the button songObj.GetComponentInChildren <Text>().enabled = false; //don't show the button text } //once the button is clicked, start the song, and if there is an error, handle it songBtn.onClick.AddListener(delegate { StartSong(songData); }); //the event is triggered when the pointer enters the trigger zone of the button EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerEnter; //if you aren't already playing the song preview start a song preview of the song entry.callback.AddListener(eventData => { if (songData.musicPath != currentSongPath) { StartCoroutine(PreviewTrack(songData.musicPath)); } }); //add the new trigger to the list of triggers in the button songBtn.GetComponent <EventTrigger>().triggers.Add(entry); } } }