GameDataSetting.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. //用来做本地数据存储的
  6. public class GameDataSetting {
  7. private const string LuminanceValue_Str = "LuminanceValue_Str";//亮度
  8. private const string BG_Sound_Switch_Str = "BG_Sound_Switch_Str";//背景音乐开关
  9. private const string Effect_Sound_Switch_Str = "Effect_Sound_Switch_Str";//音效开关
  10. private const string BG_Sound_Value_Str = "BG_Sound_Value_Str";//背景音量
  11. private const string Effect_Sound_Value_Str = "Effect_Sound_Value_Str";//特效音量
  12. private const string Cur_Instance_Value_Str = "Cur_Instance_Value_Str";//当前所在的关卡
  13. private const string Max_Instance_Value_Str = "Max_Instance_Value_Str";//最后的关卡完成情况
  14. private const string Instance_Point = "Instance_Point";//副本星星点数
  15. private const string Use_Ground_Map = "Use_Ground_Map";//使用地图
  16. private const string USER_ACCOUNT = "USER_ACCOUNT";
  17. private const string USER_PASSWORD = "USER_PASSWORD";
  18. #region 单利函数
  19. private static GameDataSetting _instance;
  20. public bool isConnectting = false;
  21. public static GameDataSetting Instance
  22. {
  23. get{
  24. if (_instance == null) {
  25. _instance = new GameDataSetting ();
  26. }
  27. return _instance;
  28. }
  29. }
  30. #endregion
  31. private GameDataSetting()
  32. {
  33. //CDebug.Log ("当前所在的关卡 " + CurInstanceValue );
  34. //CDebug.Log ("最后的关卡完成情况 " + MaxInstanceValue );
  35. }
  36. //清空所有记录
  37. public void ClearAll()
  38. {
  39. PlayerPrefs.DeleteAll ();
  40. }
  41. //亮度
  42. public float LuminanceValue
  43. {
  44. get
  45. {
  46. return PlayerPrefs.GetFloat (LuminanceValue_Str, 0.5f);
  47. }
  48. set
  49. {
  50. PlayerPrefs.SetFloat (LuminanceValue_Str, value);
  51. }
  52. }
  53. //背景音乐音量大小
  54. public float BgSoundValue
  55. {
  56. get
  57. {
  58. return PlayerPrefs.GetFloat (BG_Sound_Value_Str, 0.5f);
  59. }
  60. set
  61. {
  62. PlayerPrefs.SetFloat (BG_Sound_Value_Str, value);
  63. }
  64. }
  65. //特效音乐音量大小
  66. public float EffectSoundValue
  67. {
  68. get
  69. {
  70. return PlayerPrefs.GetFloat (Effect_Sound_Value_Str, 0.5f);
  71. }
  72. set
  73. {
  74. PlayerPrefs.SetFloat (Effect_Sound_Value_Str, value);
  75. }
  76. }
  77. //背景音乐开关
  78. public bool BGSoundSwitch
  79. {
  80. get
  81. {
  82. return PlayerPrefs.GetInt (BG_Sound_Switch_Str, 1) == 1;//默认是开启的
  83. }
  84. set
  85. {
  86. PlayerPrefs.SetInt (BG_Sound_Switch_Str, value ? 1:0 );
  87. }
  88. }
  89. //默认的用户账号
  90. public string DefaultUserAccount
  91. {
  92. get
  93. {
  94. return PlayerPrefs.GetString(USER_ACCOUNT, "");
  95. }
  96. set
  97. {
  98. PlayerPrefs.SetString(USER_ACCOUNT, value);
  99. }
  100. }
  101. //默认的用户账号
  102. public string DefaultUserPassword
  103. {
  104. get
  105. {
  106. return PlayerPrefs.GetString(USER_PASSWORD, "");
  107. }
  108. set
  109. {
  110. PlayerPrefs.SetString(USER_PASSWORD, value);
  111. }
  112. }
  113. //特效音乐开关
  114. public bool EffectSoundSwitch
  115. {
  116. get
  117. {
  118. return PlayerPrefs.GetInt (Effect_Sound_Switch_Str, 1) == 1;//默认是开启的
  119. }
  120. set
  121. {
  122. PlayerPrefs.SetInt (Effect_Sound_Switch_Str, value ? 1:0 );
  123. }
  124. }
  125. //当前所在的关卡
  126. public int CurInstanceValue
  127. {
  128. get
  129. {
  130. return PlayerPrefs.GetInt (Cur_Instance_Value_Str, 0);
  131. }
  132. set
  133. {
  134. CDebug.Log ("设置当前关卡" + value);
  135. PlayerPrefs.SetInt (Cur_Instance_Value_Str, value);
  136. }
  137. }
  138. //完成的最高的关卡
  139. public int MaxInstanceValue
  140. {
  141. get
  142. {
  143. return PlayerPrefs.GetInt (Max_Instance_Value_Str, -1);
  144. }
  145. set
  146. {
  147. PlayerPrefs.SetInt (Max_Instance_Value_Str, value);
  148. CDebug.Log ("最大关卡进度修改 " + value);
  149. }
  150. }
  151. public int GetAllPoint()
  152. {
  153. int v = 0;
  154. for (int i = 0; i < 5; i++) {
  155. v += GetInstancePoint (i);
  156. }
  157. return v;
  158. }
  159. public int GetInstancePoint(int index)
  160. {
  161. int value = 0;
  162. for (int i = 0; i < 3; i++) {
  163. if(GetInstanceTaskPoint (index, i))
  164. {
  165. value += 1;
  166. }
  167. }
  168. return value;
  169. }
  170. public bool GetInstanceTaskPoint(int instance_index, int task_index)
  171. {
  172. return PlayerPrefs.GetInt (InstanceTaskPoint(instance_index, task_index), 0) == 1;//
  173. }
  174. //设置副本任务的星星数量
  175. public void SetInstanceTaskPoint(int instance_index, int task_index)
  176. {
  177. PlayerPrefs.SetInt (InstanceTaskPoint(instance_index, task_index), 1);
  178. }
  179. private string InstanceTaskPoint(int instance_index, int task_index)
  180. {
  181. return Instance_Point + "_" +instance_index + "_" + task_index;
  182. }
  183. //使用地图
  184. public bool UseGroundMapSwitch
  185. {
  186. get
  187. {
  188. return true;
  189. return PlayerPrefs.GetInt (Use_Ground_Map, 1) == 1;//默认是开启的
  190. }
  191. set
  192. {
  193. PlayerPrefs.SetInt (Use_Ground_Map, value ? 1:0 );
  194. }
  195. }
  196. }