Ejemplo n.º 1
0
    // Start is called before the first frame update
    public void Start()
    {
        mapsContent         = mapsContent.GetComponent <Transform>();
        leaderBoard         = leaderBoard.GetComponent <Text>();
        selectedBeatMapText = selectedBeatMapText.GetComponent <Text>();
        removeBeatMapButton = removeBeatMapButton.GetComponent <Button>();
        removeBeatMapButton.onClick.AddListener(removeBeatMapListener);
        string beatMapDir = Application.persistentDataPath + "/BeatMaps/";

        Debug.Log(beatMapDir);
        Directory.CreateDirectory(beatMapDir); //create if it does not exist

        List <BeatMap> beatMaps = new List <BeatMap>();

        foreach (string fileName in Directory.EnumerateFiles(beatMapDir))
        {
            //see https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/serialization/walkthrough-persisting-an-object-in-visual-studio
            if (!fileName.EndsWith(".dat"))
            {
                continue;
            }
            BeatMap beatMap = BeatMap.loadBeatMap(fileName);
            beatMaps.Add(beatMap);
        }

        //sort beatmaps
        beatMaps.Sort((x, y) => DateTime.Compare(y.lastPlayed, x.lastPlayed));

        foreach (BeatMap beatMap in beatMaps)
        {
            GameObject             beatMapPanel = (GameObject)Instantiate(prefab, new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0), mapsContent);
            BeatMapEntryController controller   = beatMapPanel.GetComponentInChildren <BeatMapEntryController>();
            controllers.Add(controller);
            panes.Add(beatMapPanel);
            controller.instantiateBeatMaps = this;
            controller.fileName            = beatMapDir + beatMap.fileName;
            controller.setCoverArt(beatMap.songFilePath + ".png");
            controller.beatMap = beatMap;
            foreach (Text text in beatMapPanel.GetComponentsInChildren <Text>())
            {
                if (text.name == "SongName")
                {
                    text.text = beatMap.song_meta.title + " by " + beatMap.song_meta.artist;
                }
                else if (text.name == "SongInfo")
                {
                    text.text = "Times Played: " + beatMap.timesPlayed + "  Last Played: " + (beatMap.timesPlayed == 0 ? "never" : beatMap.lastPlayed.ToShortDateString() + " " + beatMap.lastPlayed.ToShortTimeString())
                                + "\nRNG Seed: " + beatMap.get_settings().rng_seed.ToString() + " Duration: " + (Mathf.FloorToInt(beatMap.get_song_info().length) / 60f).ToString("0.0") + " minutes";
                }
            }
        }
    }
    void Start()
    {
        //Screen.SetResolution(1280, 720, true, 60);
        //mainCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
        // first index is initial camera position/rotation
        //cameraPositions = new Vector3[] {mainCamera.transform.position, new Vector3(-313, -527, 1880)};
        //cameraRotations = new Quaternion[] {mainCamera.transform.rotation, Quaternion.Euler(-1.813f, -181.159f, 0)};
        warningText               = GameObject.Find("warningText");
        load_state                = LOAD_STATE.NOT_LOADED;
        _gameState                = GameState.playing;
        _playerScore              = 0;
        _playerCombo              = 1;
        _playerNotesHit           = 0;
        _playerMaxCombo           = 1;
        _pCombo                   = GameObject.Find("comboText").GetComponent <Text>();
        _pScore                   = GameObject.Find("scoreText").GetComponent <Text>();
        _playerHealth             = 100f;
        _playerHealthDecreaseRate = 1f;
        lastTime                  = Time.time;
        totalNotes                = 0;

        mainCamera = GameObject.Find("Main Camera");

        //gameOverPanel = GameObject.Find("GameOverPanel");
        gameOverPanel.SetActive(false);
        //gameOverRetryButton = GameObject.Find("GameOverRetryButton");
        //gameOverQuitButton = GameObject.Find("GameOverQuitButton");

        gameOverRetryButton.GetComponent <Button>().onClick.AddListener(handleGameOverRetry);
        gameOverQuitButton.GetComponent <Button>().onClick.AddListener(handleGameOverQuit);

        audioSrc = this.GetComponent <AudioSource>(); // there is an audiosource in beatmapplayer, but it is more convenient to create one here

        // do not render the pause canvas on launch
        //GameObject.Find("PauseCanvas").SetActive(false);

        LoadPlayerFromExternal(ref playerClass);

        // handle car visibility
        GameObject car_gt86  = GameObject.Find("car_gt86");
        GameObject car_merc  = GameObject.Find("car_merc");
        GameObject car_lambo = GameObject.Find("car_lambo");

        cars = new GameObject[] { car_gt86, car_merc, car_lambo }; // keep the order here the same as in MainMenuCanvasController

        btnSettings.onClick.AddListener(handleSettings);
        exitSettingsButton.onClick.AddListener(handleExitSettings);

        settingsPanel.SetActive(false);

        handleCarVisibility();

        beatMap = BeatMap.loadBeatMap();
        beatMap.loadSamples(this);

        objective    = GameObject.Find("Objective");
        badObjective = GameObject.Find("BadObjective");

        sounds = GetComponents <AudioSource>();

        // initial camera angle
        //mainCamera.transform.position = Vector3.MoveTowards(cameraPositions[1], cameraPositions[0], 20f);
        //mainCamera.transform.rotation = Quaternion.RotateTowards(cameraRotations[1], cameraRotations[0], 20f);


        // temp, generate gameobjects based on beatmap
        //Stream openFileStream = File.OpenRead(Application.persistentDataPath + "/BeatMaps/testBeatmap.dat");
        //BinaryFormatter deserializer = new BinaryFormatter();
        //BeatMap beatMap = (BeatMap)deserializer.Deserialize(openFileStream);
    }