/* * Loads songmaps from the Songs folder into an dictionary where the string key represents the parent song for all the songmaps under it. */ public void LoadSongmaps() { songmaps.Clear(); foreach (var dir in Directory.EnumerateDirectories(Songmap.SONGS_FOLDER)) { string key = dir.Substring(dir.LastIndexOf("\\") + 1); songmaps.Add(key, new List <Songmap>()); foreach (var file in Directory.EnumerateFiles(dir)) { if (file.Contains(Songmap.SONG_MIME_TYPE)) { try { Songmap songmap = Songmap.Load(file); songmaps[key].Add(songmap); } catch (Exception e) { print($"Exception occurred while loading file {file} as songmap. {e.ToString()}"); } } } if (songmaps[key].Count == 0) { songmaps.Remove(key); } } }
public void AddSongmapChildView(GameObject childPrefab, Songmap map) { GameObject obj = MonoBehaviour.Instantiate(childPrefab); SongmapChildView childView = new SongmapChildView(obj, map); childView.gameObject.transform.SetParent(gameObject.transform, false); childView.gameObject.SetActive(true); songmapChildViews.Add(childView); }
public SongmapChildView(GameObject gameObject, Songmap map) : base(gameObject) { songmap = map; Transform infoPanel = this.gameObject.transform.Find("HorizontalPanel").Find("InfoPanel").Find("InfoPanel (1)"); title = infoPanel.Find("ItemTitle").GetComponent <Text>(); difficulty = infoPanel.Find("ItemDifficultyName").GetComponent <Text>(); Transform highScorePanel = this.gameObject.transform.Find("HorizontalPanel").Find("HiscorePanel"); highScore = highScorePanel.Find("ItemHiscore").GetComponent <Text>(); accuracy = highScorePanel.Find("ItemAccuracy").GetComponent <Text>(); Transform gradePanel = this.gameObject.transform.Find("HorizontalPanel").Find("GradePanel"); gradeTitle = gradePanel.Find("ItemGradeTitle").GetComponent <Text>(); grade = gradePanel.Find("ItemGrade").GetComponent <RawImage>(); difficultyMask = this.gameObject.transform.Find("HorizontalPanel").Find("InfoPanel").Find("DifficultyPanel").Find("ForegroundMask").GetComponent <RectTransform>(); difficultyForeground = difficultyMask.transform.Find("DifficultyForeground").GetComponent <RectTransform>(); title.text = map.GetSongmapName(false); difficulty.text = map.DifficultyTitle; gameResult = HighScoreManager.Instance.GetGameResult(map.GetSongmapName()); if (gameResult.Score > 0) { highScore.text = HighScoreManager.GetFormattedHighscore(gameResult); accuracy.text = $"{gameResult.RoundedHitPercentage} %"; } else { highScorePanel.gameObject.SetActive(false); } if (gameResult.perfects + gameResult.normals + gameResult.poors + gameResult.misses > 0) { grade.texture = ScoreSystem.Instance.GetResultGradeTexture(gameResult.ResultGrade); gradeTitle.text = gameResult.ResultGrade.ToString(); } else { gradePanel.gameObject.SetActive(false); } float difficultyStep = (difficultyForeground.sizeDelta.x / Songmap.MAX_DIFFICULTY); float maskOffset = Songmap.MAX_DIFFICULTY * difficultyStep - difficultyStep * map.GetDifficulty(); difficultyMask.offsetMin = new Vector2(0, 0); difficultyMask.offsetMax = new Vector2(-maskOffset, 0); }
/* * Couroutine that loads the audio clip from given songmap. */ private IEnumerator LoadSongmapAudioCoroutine(Songmap songmap) { using (var www = UnityWebRequestMultimedia.GetAudioClip(songmap.GetSongmapAudioFilePath(), songmap.GetAudioType())) { yield return(www.SendWebRequest()); if (www.isNetworkError) { Debug.Log(www.error); } else { AudioSource.clip = DownloadHandlerAudioClip.GetContent(www); AudioSource.volume = .5f; sampleRate = AudioSource.clip.samples / AudioSource.clip.length; } } }
/* Starts an coroutine that loads the songmaps audio clip into the audio source. */ public void LoadSongmapAudio(Songmap songmap) { StartCoroutine(LoadSongmapAudioCoroutine(songmap)); }
/* Starts an couroutine that loads the songmaps audio clip and starts playing it. */ public void PlaySongmapAudio(Songmap songmap) { StartCoroutine(PlaySongmapAudioCoroutine(songmap)); }
/* * Couroutine that loads the audio clip from given songmap and starts playing it. */ private IEnumerator PlaySongmapAudioCoroutine(Songmap songmap) { yield return(LoadSongmapAudioCoroutine(songmap)); AudioSource.Play(); }