// To do: Put a primary key in for beatmaps public bool Equals(BeatmapSelectable b) { if (b.Name == this.Name && b.Artist == this.Artist) { return(true); } return(false); }
private int FindBeatmapIndex(BeatmapSelectable b) { for (int i = 0; i < beatmaps.Count; i++) { if (beatmaps[i].Equals(b)) { return(i); } } return(-1); }
public IEnumerator LoadBeatmapSelectionAsync() { string path = null; #if UNITY_EDITOR if (Application.isEditor) { path = Application.dataPath + "/Resources/Beatmaps"; } #endif #if UNITY_ANDROID if (Application.platform == RuntimePlatform.Android) { path = Application.persistentDataPath + "/Beatmaps"; } #endif if (Application.platform == RuntimePlatform.WindowsPlayer) { Debug.Log("Windows Datapath: " + Application.dataPath); path = Application.dataPath + "/Beatmaps"; } DirectoryInfo[] directories = new DirectoryInfo(path).GetDirectories(); for (int i = 0; i < directories.Length; i++) { BeatmapSelectable map = Instantiate(BeatmapSelectablePrefab).GetComponent <BeatmapSelectable>(); map.transform.SetParent(this.transform); map.transform.SetAsFirstSibling(); Vector3 spawnPosition = new Vector3(0, ySpawnOffset * -i, 0); map.Initialize(directories[i].Name, path + "/" + directories[i].Name, spawnPosition); beatmaps.Add(map); } if (beatmaps.Count > 0) { selectedBeatmap = beatmaps[0]; } else { Debug.LogWarning("Warning: No Beatmaps Loaded", this.transform); } yield return(true); }
private void RecalculateSelectedBeatmap() { int index = FindBeatmapIndex(selectedBeatmap); if (index < 0) { return; } if (beatmaps[index].rTransform.anchoredPosition.y > 300f) { selectedBeatmap.SetUnselected(); selectedBeatmap = beatmaps[index + 1]; selectedBeatmap.SetSelected(); } else if (beatmaps[index].rTransform.anchoredPosition.y < -300f) { selectedBeatmap.SetUnselected(); selectedBeatmap = beatmaps[index - 1]; selectedBeatmap.SetSelected(); } }