VR模拟枪支打靶,消灭鬼怪,换弹以及上弦等等硬核枪支操作。 使用HTCVive设备,开启SteamVR进行游玩。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

414 lines
13 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
//主菜单及设置
public class MainMenu : MonoBehaviour {
//第一次打开游戏?
private bool isFirstOpenGame;
//游戏设置菜单获取
public bool[] gameSetting_;
public Button[] gameSetting_LeftBtn;
public Button[] gameSetting_RightBtn;
public Text[] gameSetting_Text;
//开始两种游戏模式
public void startGhostMode() {
SceneManager.LoadScene(1);
}
public void startOutsideMode() {
SceneManager.LoadScene(2);
}
//退出游戏
public void exitGame() {
Application.Quit();
}
//主菜单设定初始化
private void Start()
{
if (SaveSystem.HasKey("isFirstOpenGame"))
{
loadingSettingAll();
}
else {
isFirstOpenGame = true;
SaveSystem.SetBool("isFirstOpenGame", isFirstOpenGame);
/**************************************/
changeAllQualityEffect();
changeTextureQualityEffect();
changeShadowQualityEffect();
changeAntiAliasingQualityEffect();
changeAnisotropicEffect();
changeVSyncEffect();
/********************************************/
}
}
//游戏设置保存
public void gameSettingSave() {
for (int i = 0;i<11;i++) {
SaveSystem.SetBool("gameSetting"+i, gameSetting_[i]);
}
}
//游戏设置读取
public void gameSettingLoad()
{
for (int i = 0; i < 11; i++)
{
gameSetting_[i] = SaveSystem.GetBool("gameSetting" + i);
if (gameSetting_[i])
{
gameSetting_LeftBtn[i].interactable = true;
gameSetting_RightBtn[i].interactable = false;
gameSetting_Text[i].text = "显示";
if (i>=6) {
gameSetting_Text[i].text = "开";
}
}
else {
gameSetting_LeftBtn[i].interactable = false;
gameSetting_RightBtn[i].interactable = true;
gameSetting_Text[i].text = "不显示";
if (i >= 8)
{
gameSetting_Text[i].text = "关";
}
}
}
}
//布尔类型的设置按钮点击事件
public void settingButtonClickBool(int gameSettingId) {
float gameSettingNo = gameSettingId / 2f;
if (Mathf.Abs(gameSettingId / 2) != gameSettingNo)
{
gameSetting_[(gameSettingId-1)/2] = false;
}
else {
gameSetting_[gameSettingId/2] = true;
}
}
//布尔类型的设置按钮加载事件
public void loadingButtonClickBool()
{
}
//画质调整方法
//1.1总画质
private int qualityLevel_ = 4;
public Button allQualitySettingLeft_;
public Button allQualitySettingRight_;
public Text allQualitySettingText_;
public void setAllQuality(bool isleft) {
if (isleft && qualityLevel_>1)
{
qualityLevel_ -= 1;
}
else if(!isleft && qualityLevel_ < 5) {
qualityLevel_ += 1;
}
changeAllQualityEffect();
}
private void changeAllQualityEffect(){
QualitySettings.SetQualityLevel(qualityLevel_);
if (qualityLevel_ == 1)
{
allQualitySettingLeft_.interactable = false;
}else
{
allQualitySettingLeft_.interactable = true;
}
if (qualityLevel_ == 5)
{
allQualitySettingRight_.interactable = false;
}else {
allQualitySettingRight_.interactable = true;
}
switch (qualityLevel_)
{
case 1:
allQualitySettingText_.text = "低";
break;
case 2:
allQualitySettingText_.text = "中等";
break;
case 3:
allQualitySettingText_.text = "高";
break;
case 4:
allQualitySettingText_.text = "极高";
break;
case 5:
allQualitySettingText_.text = "完美";
break;
}
}
//1.2全局雾效/泛光/SSAO参照上述游戏设置
//1.3贴图质量
private int textureQualityLevel_ = 0;
public Button textureQualitySettingLeft_;
public Button textureQualitySettingRight_;
public Text textureQualitySettingText_;
public void setTextureQuality(bool isleft)
{
if (isleft && textureQualityLevel_ < 3)
{
textureQualityLevel_ += 1;
}
else if (!isleft && textureQualityLevel_ > 0)
{
textureQualityLevel_ -= 1;
}
changeTextureQualityEffect();
}
private void changeTextureQualityEffect() {
QualitySettings.masterTextureLimit = textureQualityLevel_;
if (textureQualityLevel_ == 0)
{
textureQualitySettingRight_.interactable = false;
}
else {
textureQualitySettingRight_.interactable = true;
}
if (textureQualityLevel_ == 3)
{
textureQualitySettingLeft_.interactable = false;
}
else {
textureQualitySettingLeft_.interactable = true;
}
switch (textureQualityLevel_) {
case 0:
textureQualitySettingText_.text = "完美";
break;
case 1:
textureQualitySettingText_.text = "一般";
break;
case 2:
textureQualitySettingText_.text = "较差";
break;
case 3:
textureQualitySettingText_.text = "差";
break;
}
}
//1.4阴影质量
private int shadowQualityLevel_ = 2;
public Button shadowQualitySettingLeft_;
public Button shadowQualitySettingRight_;
public Text shadowQualitySettingText_;
public void setShadowQuality(bool isleft)
{
if (isleft && shadowQualityLevel_ > 0)
{
shadowQualityLevel_ -= 1;
}
else if (!isleft && shadowQualityLevel_ < 2)
{
shadowQualityLevel_ += 1;
}
changeShadowQualityEffect();
}
private void changeShadowQualityEffect() {
if (shadowQualityLevel_ == 2)
{
shadowQualitySettingRight_.interactable = false;
}
else
{
shadowQualitySettingRight_.interactable = true;
}
if (shadowQualityLevel_ == 0)
{
shadowQualitySettingLeft_.interactable = false;
}
else
{
shadowQualitySettingLeft_.interactable = true;
}
switch (shadowQualityLevel_) {
case 0:
QualitySettings.shadows = ShadowQuality.Disable;
shadowQualitySettingText_.text = "无阴影";
break;
case 1:
QualitySettings.shadows = ShadowQuality.HardOnly;
shadowQualitySettingText_.text = "只有硬阴影";
break;
case 2:
QualitySettings.shadows = ShadowQuality.All;
shadowQualitySettingText_.text = "全部阴影";
break;
}
}
//1.5抗锯齿
private int antiAliasingQualityLevel_ = 1;
public Button antiAliasingQualitySettingLeft_;
public Button antiAliasingQualitySettingRight_;
public Text antiAliasingQualitySettingText_;
public void setAntiAliasingQuality(bool isleft)
{
if (isleft && antiAliasingQualityLevel_ > 0)
{
antiAliasingQualityLevel_ -= 1;
}
else if (!isleft && antiAliasingQualityLevel_ < 3)
{
antiAliasingQualityLevel_ += 1;
}
changeAntiAliasingQualityEffect();
}
private void changeAntiAliasingQualityEffect()
{
if (antiAliasingQualityLevel_ > 2)
QualitySettings.antiAliasing = antiAliasingQualityLevel_ * 2 + 2;
else
QualitySettings.antiAliasing = antiAliasingQualityLevel_ * 2;
if (antiAliasingQualityLevel_ == 3)
{
antiAliasingQualitySettingRight_.interactable = false;
}
else
{
antiAliasingQualitySettingRight_.interactable = true;
}
if (antiAliasingQualityLevel_ == 0)
{
antiAliasingQualitySettingLeft_.interactable = false;
}
else
{
antiAliasingQualitySettingLeft_.interactable = true;
}
switch (antiAliasingQualityLevel_)
{
case 0:
antiAliasingQualitySettingText_.text = "关闭";
break;
case 1:
antiAliasingQualitySettingText_.text = "2x";
break;
case 2:
antiAliasingQualitySettingText_.text = "4x";
break;
case 3:
antiAliasingQualitySettingText_.text = "8x";
break;
}
}
//1.6各项异性纹理过滤
private bool openAnisotropicTextures = true;
public Button anisotropicButtonLeft_;
public Button anisotropicButtonRight_;
public Text anisotropicText_;
public void setAnisotropicQuality(bool isleft)
{
if (isleft && openAnisotropicTextures)
{
openAnisotropicTextures = false;
}
else if (!isleft && !openAnisotropicTextures)
{
openAnisotropicTextures = true;
}
changeAnisotropicEffect();
}
private void changeAnisotropicEffect() {
if (openAnisotropicTextures) {
QualitySettings.anisotropicFiltering = AnisotropicFiltering.Enable;
anisotropicButtonLeft_.interactable = true;
anisotropicButtonRight_.interactable = false;
anisotropicText_.text = "开";
}
else {
QualitySettings.anisotropicFiltering = AnisotropicFiltering.Disable;
anisotropicButtonLeft_.interactable = false;
anisotropicButtonRight_.interactable = true;
anisotropicText_.text = "关";
}
}
//1.7垂直同步
private bool openVSync = true;
public Button vSyncButtonLeft_;
public Button vSyncButtonRight_;
public Text vSyncText_;
public void setVSyncQuality(bool isleft)
{
if (isleft && openVSync)
{
openVSync = false;
}
else if (!isleft && !openVSync)
{
openVSync = true;
}
changeVSyncEffect();
}
private void changeVSyncEffect()
{
if (openVSync)
{
QualitySettings.vSyncCount = 1;
vSyncButtonRight_.interactable = false;
vSyncButtonLeft_.interactable = true;
vSyncText_.text = "开";
}
else
{
QualitySettings.vSyncCount = 0;
vSyncButtonLeft_.interactable = false;
vSyncButtonRight_.interactable = true;
vSyncText_.text = "关";
}
}
//获取音量调整控件
public Slider volume_1;
public Slider volume_2;
public Slider volume_3;
//保存设置
public void saveSettingAll() {
//保存游戏设置/全局雾效/泛光/SSAO
gameSettingSave();
//保存画质设置
SaveSystem.SetInt("videoSetting1", qualityLevel_);
SaveSystem.SetInt("videoSetting2", textureQualityLevel_);
SaveSystem.SetInt("videoSetting3", shadowQualityLevel_);
SaveSystem.SetInt("videoSetting4", antiAliasingQualityLevel_);
SaveSystem.SetBool("videoSetting5", openAnisotropicTextures);
SaveSystem.SetBool("videoSetting6", openVSync);
//保存音量设置
SaveSystem.SetFloat("volumeSetting1",volume_1.value);
SaveSystem.SetFloat("volumeSetting2", volume_2.value);
SaveSystem.SetFloat("volumeSetting3", volume_3.value);
}
//加载设置
public void loadingSettingAll() {
gameSettingLoad();
//加载画质设置
qualityLevel_ = SaveSystem.GetInt("videoSetting1");
textureQualityLevel_ = SaveSystem.GetInt("videoSetting2");
shadowQualityLevel_ = SaveSystem.GetInt("videoSetting3");
antiAliasingQualityLevel_ = SaveSystem.GetInt("videoSetting4");
openAnisotropicTextures = SaveSystem.GetBool("videoSetting5");
openVSync = SaveSystem.GetBool("videoSetting6");
//加载音量设置
volume_1.value = SaveSystem.GetFloat("volumeSetting1");
volume_2.value = SaveSystem.GetFloat("volumeSetting2");
volume_3.value = SaveSystem.GetFloat("volumeSetting3");
//应用对应设置
changeAllQualityEffect();
changeTextureQualityEffect();
changeShadowQualityEffect();
changeAntiAliasingQualityEffect();
changeAnisotropicEffect();
changeVSyncEffect();
}
}