(client) feat:添加设置类,子弹添加敌我识别; chore:修改了右键菜单的初始化方式为独立创建,加载定义报错提供更多信息,动画加载出错也返回默认序列。

This commit is contained in:
m0_75251201
2025-08-19 14:36:22 +08:00
parent f67aca0804
commit f4cd5f4a86
57 changed files with 1000 additions and 788 deletions

View File

@ -0,0 +1,90 @@
using Newtonsoft.Json;
using UnityEngine;
namespace Base
{
public class Setting : Utils.Singleton<Setting>
{
// 游戏设置数据类(用于序列化)
[System.Serializable]
public class GameSettings
{
public float progressStepDuration = 1f;
public float exitAnimationDuration = 2f;
public bool developerMode = false;
public bool friendlyFire = false;
public float globalVolume = 1.0f;
public WindowMode currentWindowMode = WindowMode.Fullscreen;
public Vector2Int windowResolution = new(1920, 1080);
}
// 当前游戏设置
public GameSettings CurrentSettings = new();
// 窗口模式枚举
public enum WindowMode { Fullscreen, Windowed, Borderless }
// 常用分辨率选项
public static readonly Vector2Int[] CommonResolutions = new Vector2Int[]
{
new(800, 600),
new(1024, 768),
new(1280, 720),
new(1366, 768),
new(1600, 900),
new(1920, 1080),
new(2560, 1440),
new(3840, 2160)
};
// 初始化加载设置
public void Init()
{
LoadSettings();
}
public void SaveSettings()
{
string json = JsonConvert.SerializeObject(CurrentSettings);
PlayerPrefs.SetString("GameSettings", json);
PlayerPrefs.Save();
}
public void LoadSettings()
{
if (PlayerPrefs.HasKey("GameSettings"))
{
string json = PlayerPrefs.GetString("GameSettings");
CurrentSettings = JsonConvert.DeserializeObject<GameSettings>(json);
}
// 应用加载的设置
ApplyAudioSettings();
ApplyWindowSettings();
}
// 应用音频设置
private void ApplyAudioSettings()
{
AudioListener.volume = Mathf.Clamp01(CurrentSettings.globalVolume);
}
// 应用窗口设置
private void ApplyWindowSettings()
{
switch (CurrentSettings.currentWindowMode)
{
case WindowMode.Fullscreen:
Screen.SetResolution(CurrentSettings.windowResolution.x, CurrentSettings.windowResolution.y, FullScreenMode.FullScreenWindow);
break;
case WindowMode.Windowed:
Screen.SetResolution(CurrentSettings.windowResolution.x, CurrentSettings.windowResolution.y, FullScreenMode.Windowed);
break;
case WindowMode.Borderless:
Screen.SetResolution(CurrentSettings.windowResolution.x, CurrentSettings.windowResolution.y, FullScreenMode.MaximizedWindow);
break;
}
}
}
}