コード例 #1
0
ファイル: SettingsMenu.cs プロジェクト: magweng/imt3601
    // Set up the content of the settings menu here
    private void generateMenu()
    {
        GameObject panel = transform.GetChild(0).GetChild(1).GetChild(0).GetChild(0).gameObject; // Yep


        // VIDEO SETTINGS:
        GameObject videoSettings = addSection("Video", panel);

        string[]   resolutions = new string[] { "2560x1440", "1920x1080", "1280x720", "1024x768" };
        GameObject resolution  = addDropdownOption("Resolution",
                                                   videoSettings,
                                                   resolutions,
                                                   delegate { // Update screen resolution
            string[] dimensions = resolutions[PlayerPrefs.GetInt("Resolution")].Split('x');
            Screen.SetResolution(Int32.Parse(dimensions[0]), Int32.Parse(dimensions[1]), Screen.fullScreen);
            return(null);
        }
                                                   );

        GameObject windowMode = addDropdownOption("Window Mode",
                                                  videoSettings,
                                                  new string[] { "Windowed", "Fullscreen" },
                                                  delegate {
            Screen.fullScreen = PlayerPrefs.GetInt("Window Mode", 0) == 1;
            return(null);
        }
                                                  );

        GameObject vsync = addDropdownOption("Vsync",
                                             videoSettings,
                                             new string[] { "Off", "On" },
                                             delegate {
            QualitySettings.vSyncCount = PlayerPrefs.GetInt("Vsync", 1);
            return(null);
        }
                                             );



        // CAMERA SETTINGS:
        GameObject cameraSection = addSection("Camera", panel);

        GameObject fov = addSliderOption("Field of View", cameraSection, 40, 100,
                                         delegate {
            ThirdPersonCamera tpc = GameObject.Find("Main Camera").GetComponent <ThirdPersonCamera>();
            if (tpc != null)
            {
                tpc.SetFOV(PlayerPrefs.GetFloat("Field of View", 60));
            }
            return(null);
        }
                                         );
        GameObject mouseSensitivity = addSliderOption("Mouse Sensitivity", cameraSection, 2, 20,
                                                      delegate {
            ThirdPersonCamera tpc = GameObject.Find("Main Camera").GetComponent <ThirdPersonCamera>();
            if (tpc != null)
            {
                tpc.SetSensitivity(PlayerPrefs.GetFloat("Mouse Sensitivity", 10));
            }
            return(null);
        }
                                                      );


        // Audio has not yet been implemented, so these settings currently doesn't really do anything
        // AUDIO SETTINGS:
        GameObject soundSection = addSection("Sound", panel);

        GameObject masterVolume = addSliderOption("Master Volume", soundSection, 0, 100,
                                                  () => {
            if (GameObject.Find("AudioManager"))
            {
                GameObject.Find("AudioManager").GetComponent <AudioManager>().updateVolume();
            }
            return(null);
        });
        GameObject musicVolume  = addSliderOption("Music Volume", soundSection, 0, 100);
        GameObject effectVolume = addSliderOption("Effect Volume", soundSection, 0, 100);



        // TODO: Add a blocker, so you can't click on anything else while the settings panel is open

        pack(panel);
    }