Example #1
0
 private void Start()
 {
     options             = SaveSystem.GetOptions();
     audioSource         = GetComponent <AudioSource>();
     optionsMenuScript   = GetComponent <OptionsMenu>();
     audioSourceGameLoop = GameObject.FindGameObjectWithTag("GameManager").GetComponent <AudioSource>();
 }
Example #2
0
    private void Start()
    {
        audioSource = GetComponent <AudioSource>();
        resolutions = Screen.resolutions.Select(x => new Resolution {
            width = x.width, height = x.height
        }).Distinct().Reverse().ToList();
        refreshRates = Screen.resolutions.Select(x => x.refreshRate).Distinct().Reverse().ToList();
        resolutions.ForEach(x => resolutionDropdown.options.Add(new TMP_Dropdown.OptionData($"{x.width} x {x.height}")));
        refreshRates.ForEach(x => refreshRateDropdown.options.Add(new TMP_Dropdown.OptionData($"{x} hz")));

        options = SaveSystem.GetOptions();

        if (options.Resolution.Width == 0 || options.Resolution.Height == 0 || options.Resolution.RefreshRate == 0)
        {
            options.Resolution.Width       = Screen.currentResolution.width;
            options.Resolution.Height      = Screen.currentResolution.height;
            options.Resolution.RefreshRate = Screen.currentResolution.refreshRate;
        }

        SetOptionValues();
        options.OptionsChanged.AddListener(OptionsUpdated);
        options.Resolution.ResolutionChanged.AddListener(OptionsUpdated);

        Screen.SetResolution(options.Resolution.Width, options.Resolution.Height, options.Fullscreen, options.Resolution.RefreshRate);
        Application.targetFrameRate = options.Resolution.RefreshRate;
    }
Example #3
0
    private void Start()
    {
#if !DEBUG
        if (Game.Instance is null)
        {
            SceneManager.LoadScene("GameMenu");
            return;
        }
#endif

        if (NewHighscore)
        {
            scoreTextLabel.text  = "New Highscore!";
            scoreTextLabel.color = Color.green;
            scoreText.color      = Color.green;
        }

        audioSource    = GetComponent <AudioSource>();
        options        = SaveSystem.GetOptions();
        scoreText.text = AddCommas(Score);

        if (options.SoundEffects)
        {
            audioSource.Play();
        }
    }
    public void ApplySettings()
    {
        //Store results in static class and get them to update
        SavedOptions.MusicVolume      = Mathf.RoundToInt(musicSlider.value);
        SavedOptions.InputSensitivity = sensitivitySlider.value;

        SavedOptions.UpdatePlayingMusicVolume();
    }
Example #5
0
    private void OnApplicationFocus(bool focus)
    {
        options = SaveSystem.GetOptions();

        if (!focus && !optionsMenu.activeSelf && !saveMenu.activeSelf && !playMenu.activeSelf && !controlsMenu.activeSelf && options.AutoPauseOnFocusLose)
        {
            Pause(false);
        }
    }
Example #6
0
    /// <summary>
    /// Cancels the changes
    /// </summary>
    public void Cancel(bool goBack)
    {
        audioSource.Play();

        if (goBack && OptionsChanged)
        {
            dialog.OnResult += (Dialog.DialogResult result) =>
            {
                if (result == Dialog.DialogResult.Yes)
                {
                    options = SaveSystem.GetOptions();
                    options.OptionsChanged.AddListener(OptionsUpdated);
                    options.Resolution.ResolutionChanged.AddListener(OptionsUpdated);

                    changeOptions = false;
                    SetOptionValues();

                    OptionsChanged = false;
                    changeOptions  = true;
                    okButton.gameObject.SetActive(false);
                    applyButton.gameObject.SetActive(false);
                    cancelButton.gameObject.SetActive(false);
                    backButton.gameObject.SetActive(true);

                    Back();
                }
            };

            dialog.Open(Dialog.DialogType.YesNo, "Are you sure that you want to cancel the changes and go back?");
        }
        else
        {
            if (OptionsChanged)
            {
                options = SaveSystem.GetOptions();
                options.OptionsChanged.AddListener(OptionsUpdated);
                options.Resolution.ResolutionChanged.AddListener(OptionsUpdated);

                changeOptions = false;
                SetOptionValues();

                OptionsChanged = false;
                changeOptions  = true;
                okButton.gameObject.SetActive(false);
                applyButton.gameObject.SetActive(false);
                cancelButton.gameObject.SetActive(false);
                backButton.gameObject.SetActive(true);
            }

            if (goBack)
            {
                Back();
            }
        }
    }
    /// <summary>
    /// Triggers the shake effect
    /// </summary>
    /// <param name="duration">The duration of the shake effect</param>
    /// <param name="magnitude">How much it shoulf shake</param>
    /// <param name="damping">How quickly the shake should evaporate</param>
    public void TriggerShake(float duration = 1, float magnitude = 1, float damping = 1)
    {
        options = SaveSystem.GetOptions();

        if (options.ShakingEffect)
        {
            shakeMagnitude = magnitude;
            dampingSpeed   = damping;
            shakeDuration  = duration;
        }
    }
Example #8
0
    private void Start()
    {
        Application.quitting += () => UpdateHighscores();

        audioSource       = GetComponents <AudioSource>().FirstOrDefault(x => x.clip.name == "gameloop");
        buttonAudioSource = GetComponents <AudioSource>().FirstOrDefault(x => x.clip.name == "buttonclick");
        Options           = SaveSystem.GetOptions();
        GetControls();
        Grid          = new Transform[GridWidth, GridHeight];
        spawnPosition = new Vector2(GridWidth / 2, GridHeight);

        CurrentScore = 0;
        CurrentLevel = StartingLevel;
        HighScores   = SaveSystem.GetHighscores();

        tetrominos = GameObject.Find("Tetrominos").transform;

        if (SaveGame != null)
        {
            if (Options.BackgroundMusic)
            {
                audioSource.Play();
            }

            CurrentScore      = SaveGame.Score;
            TotalLinesCleared = SaveGame.Lines;
            Name = SaveGame.Name;

            foreach (SavedMino savedMino in SaveGame.Minos)
            {
                GameObject mino = Instantiate(GetMino(savedMino.Name), new Vector3(savedMino.PositionX, savedMino.PositionY), Quaternion.identity, tetrominos);
                Grid[savedMino.PositionX, savedMino.PositionY] = mino.transform;
            }

            SpawnTetromino(new Vector2(SaveGame.CurrentTetromino.PositionX, SaveGame.CurrentTetromino.PositionY), SaveGame.CurrentTetromino.RotationZ, SaveGame.CurrentTetromino.Name, SaveGame.NextTetromino.Name);

            if (SaveGame.SavedTetromino != null)
            {
                SaveTetromino((GameObject)Resources.Load(GetTetromino(SaveGame.SavedTetromino.Name)), true);
            }

            Time.timeScale = 1;
        }
        else
        {
            Time.timeScale = 0;
            playMenu.SetActive(true);
            nameField.Select();
        }
    }
Example #9
0
    /// <summary>
    /// Unpauses the game
    /// </summary>
    private void UnPause()
    {
        if (optionsMenuScript is null || optionsMenuScript.OptionsChanged)
        {
            return;
        }

        if (ControlsMenu.Instance != null && ControlsMenu.Instance.ControlsChanged)
        {
            dialog.OnResult += (Dialog.DialogResult result) =>
            {
                if (result == Dialog.DialogResult.Yes)
                {
                    options = SaveSystem.GetOptions();
                    audioSource.Play();
                    pauseMenu.SetActive(false);
                    optionsMenu.SetActive(false);
                    saveMenu.SetActive(false);
                    controlsMenu.SetActive(false);
                    if (options != null && options.BackgroundMusic)
                    {
                        audioSourceGameLoop.Play();
                    }

                    ControlsMenu.Instance.Cancel(false);
                    Game.Instance.IsPaused = false;
                    Time.timeScale         = 1;
                }
            };

            dialog.Open(Dialog.DialogType.YesNo, "Are you sure that you want to cancel the changes?");
        }
        else
        {
            options = SaveSystem.GetOptions();
            audioSource.Play();
            pauseMenu.SetActive(false);
            optionsMenu.SetActive(false);
            saveMenu.SetActive(false);
            controlsMenu.SetActive(false);
            if (options != null && options.BackgroundMusic)
            {
                audioSourceGameLoop.Play();
            }

            Game.Instance.IsPaused = false;
            Time.timeScale         = 1;
        }
    }
Example #10
0
    /// <summary>
    /// Saves the options
    /// </summary>
    /// <param name="options">The options to save</param>
    /// <returns>If saving the options was a success</returns>
    public static bool SaveOptions(SavedOptions options)
    {
        SaveSystem.options = new SavedOptions(options);
        BinaryFormatter formatter = new BinaryFormatter();
        MemoryStream    stream    = new MemoryStream();

        try
        {
            formatter.Serialize(stream, options);
            File.WriteAllBytes(GetOptionsPath(), stream.ToArray());
            return(true);
        }
        catch (SerializationException)
        {
            return(false);
        }
    }
Example #11
0
    /// <summary>
    /// Gets the saved options
    /// </summary>
    /// <returns>The saved options</returns>
    public static SavedOptions GetOptions()
    {
        if (SaveSystem.options != null)
        {
            return(new SavedOptions(SaveSystem.options));
        }

        SavedOptions    options   = new SavedOptions();
        BinaryFormatter formatter = new BinaryFormatter();
        MemoryStream    stream    = new MemoryStream();

        try
        {
            if (File.Exists(GetOptionsPath()))
            {
                byte[] bytes = File.ReadAllBytes(GetOptionsPath());
                stream.Write(bytes, 0, bytes.Length);
                stream.Position = 0;
                SavedOptions loadedOptions = formatter.Deserialize(stream) as SavedOptions;

                options.BackgroundMusic      = loadedOptions.BackgroundMusic;
                options.SoundEffects         = loadedOptions.SoundEffects;
                options.ShakingEffect        = loadedOptions.ShakingEffect;
                options.Fullscreen           = loadedOptions.Fullscreen;
                options.AutoPauseOnFocusLose = loadedOptions.AutoPauseOnFocusLose;

                options.Resolution.Width       = loadedOptions.Resolution.Width;
                options.Resolution.Height      = loadedOptions.Resolution.Height;
                options.Resolution.RefreshRate = loadedOptions.Resolution.RefreshRate;
            }
            else
            {
                SaveOptions(options);
            }
        }
        catch (SerializationException)
        {
            SaveOptions(options);
        }

        SaveSystem.options = new SavedOptions(options);
        return(options);
    }
Example #12
0
 private void Start()
 {
     options = SaveSystem.GetOptions();
 }