少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Events;
using System;
using vnxbqy.UI;
using System.Collections;
 
 
public class SystemSetting : Singleton<SystemSetting>
 
{
    const string QUALITY_LEVEL_KEY = "GameQualityLevel";
    const string SOUND_VOLUME_KEY = "SoundRatioKey";  //音乐
    const string SOUND_EFFECT_KEY = "SoundEffect"; //音效
    const string GAMEFRAME_KEY = "GameFrameSetting";//垂直同步率
 
    public Dictionary<SystemSwitch, bool> systemSettings = new Dictionary<SystemSwitch, bool>();
 
    int m_PlayerSyncCount = -1;
 
    public event Action<SystemSwitch, bool> OnSettingChanged;
    public event Action qualityLevelChangeEvent;
    public event Action playerSyncCountChangeEvent;
    public event Action gameFrameChangeEvent;
 
    public SystemSetting()
    {
        DTC0102_tagCDBPlayer.switchAccountEvent += OnSwitchAccount;
    }
 
    ~SystemSetting()
    {
        DTC0102_tagCDBPlayer.switchAccountEvent -= OnSwitchAccount;
    }
 
    public void SetSoundVolume(float _volume)
    {
        LocalSave.SetFloat(SOUND_VOLUME_KEY, Mathf.Clamp01(_volume));
        SoundPlayer.Instance.musicAudioSource.volume = Mathf.Clamp01(_volume);
    }
 
    public float GetSoundVolume()
    {
        return LocalSave.GetFloat(SOUND_VOLUME_KEY, .55f);
    }
 
    public void SetSoundEffect(float value)
    {
        LocalSave.SetFloat(SOUND_EFFECT_KEY, Mathf.Clamp01(value));
    }
 
    public float GetSoundEffect()
    {
        return LocalSave.GetFloat(SOUND_EFFECT_KEY, .8f);
    }
 
    public void SetGameFps(GameFps _frame)
    {
        LocalSave.SetInt(GAMEFRAME_KEY, (int)_frame);
        Application.targetFrameRate = Mathf.Clamp((int)_frame, 30, 60);
        if (gameFrameChangeEvent != null)
        {
            gameFrameChangeEvent();
        }
    }
 
    public GameFps GetGameFps()
    {
        return (GameFps)LocalSave.GetInt(GAMEFRAME_KEY, (int)GameFps.Full);
    }
 
    public void SetSystemSettingSwitch(SystemSwitch type, bool _value)
    {
        SettingMgr.Instance.SetAccountSetStr(type.ToString(), _value.ToString());
        systemSettings[type] = _value;
 
        if (OnSettingChanged != null)
        {
            OnSettingChanged(type, _value);
        }
    }
 
    public bool GetSystemSettingSwitch(SystemSwitch type)
    {
        if (systemSettings.ContainsKey(type))
        {
            return systemSettings[type];
        }
        else
        {
            return systemSettings[type] = SettingMgr.Instance.GetAccountSetBoolInfo(type.ToString()); ;
        }
    }
 
    public void SetPlayerSyncCount(int _syncCount)
    {
        LocalSave.SetInt("PlayerSyncCount", _syncCount);
        if (m_PlayerSyncCount != _syncCount)
        {
            m_PlayerSyncCount = _syncCount;
            if (playerSyncCountChangeEvent != null)
            {
                playerSyncCountChangeEvent();
            }
        }
    }
 
    public int GetPlayerSyncCount()
    {
        if (m_PlayerSyncCount == -1)
        {
            var result = LocalSave.GetInt("PlayerSyncCount", -1);
            if (result == -1)
            {
                var quality = GetCurrentQualityLevel();
                switch (quality)
                {
                    case GameQuality.High:
                        m_PlayerSyncCount = 10;
                        break;
                    case GameQuality.Low:
                        m_PlayerSyncCount = 3;
                        break;
                    case GameQuality.Medium:
                        m_PlayerSyncCount = 5;
                        break;
                }
            }
            else
            {
                m_PlayerSyncCount = Mathf.Clamp(result, 0, 20);
            }
        }
 
        return m_PlayerSyncCount;
    }
 
    public void SetQualityLevel(GameQuality _quality, bool _disabeCamera = true)
    {
        LocalSave.SetInt(QUALITY_LEVEL_KEY, Mathf.Clamp((int)_quality, 0, 2));
        QualitySettings.SetQualityLevel(Mathf.Clamp((int)_quality, 0, 2));
        switch (_quality)
        {
            case GameQuality.Low:
                Shader.globalMaximumLOD = 300;
                Shader.DisableKeyword("QUALITY_HGH");
                Shader.DisableKeyword("QUALITY_MED");
                Shader.EnableKeyword("QUALITY_LOW");
                break;
            case GameQuality.Medium:
                Shader.globalMaximumLOD = 300;
                Shader.DisableKeyword("QUALITY_HGH");
                Shader.EnableKeyword("QUALITY_MED");
                Shader.DisableKeyword("QUALITY_LOW");
                break;
            case GameQuality.High:
                Shader.globalMaximumLOD = 500;
                Shader.EnableKeyword("QUALITY_HGH");
                Shader.DisableKeyword("QUALITY_MED");
                Shader.DisableKeyword("QUALITY_LOW");
                break;
        }
 
#if UNITY_ANDROID && !UNITY_EDITOR
        if (_disabeCamera)
        {
            CameraManager.uiCamera.enabled = false;
        }
 
        ResolutionUtility.AdjustResolution(_quality);
        if (_disabeCamera)
        {
            SnxxzGame.Instance.StartCoroutine(Co_WaitFewMinute());
        }
#endif
 
        if (qualityLevelChangeEvent != null)
        {
            qualityLevelChangeEvent();
        }
 
    }
 
    public GameQuality GetCurrentQualityLevel()
    {
        //目前看起来所有的安卓机跑高效果都可以接受,先给玩家默认设置高效果。
        if (Application.platform == RuntimePlatform.Android)
        {
            if (!LocalSave.HasKey(QUALITY_LEVEL_KEY))
            {
                var defaultQuality = GameQuality.High;
                if (DeviceUtility.cpu >= 4 && DeviceUtility.memory > 3.2f * 1024)
                {
                    defaultQuality = GameQuality.High;
                }
                else if (DeviceUtility.cpu >= 4 && DeviceUtility.memory > 2.5f * 1024)
                {
                    defaultQuality = GameQuality.Medium;
                }
                else if (DeviceUtility.cpu > 1 && DeviceUtility.memory > 1.5f * 1024)
                {
                    defaultQuality = GameQuality.Low;
                }
 
                return (GameQuality)LocalSave.GetInt(QUALITY_LEVEL_KEY, (int)defaultQuality);
            }
            else
            {
                return (GameQuality)LocalSave.GetInt(QUALITY_LEVEL_KEY);
            }
        }
        else
        {
            return (GameQuality)LocalSave.GetInt(QUALITY_LEVEL_KEY, (int)GameQuality.High);
        }
    }
 
    public void LetFPSUnLimit()
    {
        Application.targetFrameRate = 1000;
    }
 
    private void OnSwitchAccount()
    {
        systemSettings.Clear();
        m_PlayerSyncCount = -1;
    }
 
    private GameFps GetRecommendFps()
    {
        if (Screen.width * Screen.height > (1920 * 1080 + 10000))
        {
            return GameFps.Half;
        }
        else
        {
            return GameFps.Full;
        }
    }
 
    IEnumerator Co_WaitFewMinute()
    {
        yield return WaitingForSecondConst.WaitMS500;
        CameraManager.uiCamera.enabled = true;
    }
}
 
public enum SystemSwitch
{
    OtherPlayer,          //是否显示其他玩家
    HideMonster,   //是否显示普通小怪
}
 
public enum GameQuality
{
    Low = 0,
    Medium = 1,
    High = 2,
}
 
public enum GameFps
{
    Free = -1,
    Half = 30,
    Full = 60,
}