Пример #1
0
    public void LoadSong()
    {
        SongPreview.Stop();
        var song = SongInfos.GetCurrentSong();

        if (song.PlayingMethods[0].Difficulties.Count > 1)
        {
            var LevelChooser = MenuPanels.ToList().First(m => m.name == "DifficultChooser");

            foreach (var gameObj in LevelChooser.GetComponentsInChildren <Button>(true))
            {
                if (gameObj.gameObject.name == "ButtonTemplate")
                {
                    continue;
                }

                Destroy(gameObj.gameObject);
            }

            DisplayPanel("DifficultChooser");

            var buttonsCreated = new List <GameObject>();

            PlayingMethod playingMethod = song.PlayingMethods[0];
            foreach (var difficulty in playingMethod.Difficulties)
            {
                var button = GameObject.Instantiate(LevelButtonTemplate, LevelChooser.transform);

                button.GetComponentInChildren <Text>().text = difficulty;
                button.GetComponentInChildren <Button>().onClick.AddListener(() => StartSceneWithDifficulty(0, difficulty));
                button.SetActive(true);
                buttonsCreated.Add(button);
            }

            float leftAlign = (-250 - 36) * (buttonsCreated.Count / 2);
            if (buttonsCreated.Count % 2 == 0)
            {
                leftAlign -= ((-250 - 36) / 2);
            }
            foreach (var button in buttonsCreated)
            {
                button.GetComponent <RectTransform>().localPosition = new Vector3(leftAlign, buttonsCreated[0].GetComponent <RectTransform>().localPosition.y);
                leftAlign += (250 + 36);
            }
        }
        else
        {
            StartSceneWithDifficulty(0, song.PlayingMethods[0].Difficulties[0]);
        }
    }
Пример #2
0
    private void OnEnable()
    {
        string path = Path.Combine(Application.dataPath + "/Playlists");

        if (Directory.Exists(path))
        {
            foreach (var dir in Directory.GetDirectories(path))
            {
                if (Directory.Exists(dir) && Directory.GetFiles(dir, "info.dat").Length > 0)
                {
                    JSONObject infoFile = JSONObject.Parse(File.ReadAllText(Path.Combine(dir, "info.dat")));

                    var song = new Song();
                    song.Path           = dir;
                    song.Name           = infoFile.GetString("_songName");
                    song.AuthorName     = infoFile.GetString("_songAuthorName");
                    song.BPM            = infoFile.GetNumber("_beatsPerMinute").ToString();
                    song.CoverImagePath = Path.Combine(dir, infoFile.GetString("_coverImageFilename"));
                    song.AudioFilePath  = Path.Combine(dir, infoFile.GetString("_songFilename"));
                    song.PlayingMethods = new List <PlayingMethod>();

                    var difficultyBeatmapSets = infoFile.GetArray("_difficultyBeatmapSets");
                    foreach (var beatmapSets in difficultyBeatmapSets)
                    {
                        PlayingMethod playingMethod = new PlayingMethod();
                        playingMethod.CharacteristicName = beatmapSets.Obj.GetString("_beatmapCharacteristicName");
                        playingMethod.Difficulties       = new List <string>();

                        foreach (var difficultyBeatmaps in beatmapSets.Obj.GetArray("_difficultyBeatmaps"))
                        {
                            playingMethod.Difficulties.Add(difficultyBeatmaps.Obj.GetString("_difficulty"));
                        }

                        song.PlayingMethods.Add(playingMethod);
                    }

                    AllSongs.Add(song);
                }
            }
        }
    }