EditorUser.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using Newtonsoft.Json;
  4. using UnityEditor;
  5. using UnityEngine;
  6. public static class EditorUser
  7. {
  8. [MenuItem("用户/Blue/自动定位", false)]
  9. static void BlueAutoImmersalSet()
  10. {
  11. CheckType();
  12. BlueUserListConfig[0].Auto = !BlueUserListConfig[0].Auto;
  13. string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
  14. WriteUserListConfig(jsonData);
  15. Menu.SetChecked("用户/Blue/自动定位", BlueUserListConfig[0].Auto);
  16. }
  17. [MenuItem("用户/Blue/文心一言", false)]
  18. static void BlueERNIEBotSet()
  19. {
  20. CheckType();
  21. BlueUserListConfig[0].ERNIEBot = !BlueUserListConfig[0].ERNIEBot;
  22. string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
  23. WriteUserListConfig(jsonData);
  24. Menu.SetChecked("用户/Blue/文心一言", BlueUserListConfig[0].ERNIEBot);
  25. }
  26. [MenuItem("用户/文创/自动定位", false)]
  27. static void WenChuangAutoImmersalSet()
  28. {
  29. CheckType();
  30. BlueUserListConfig[1].Auto = !BlueUserListConfig[1].Auto;
  31. string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
  32. WriteUserListConfig(jsonData);
  33. Menu.SetChecked("用户/文创/自动定位", BlueUserListConfig[1].Auto);
  34. }
  35. [MenuItem("用户/文创/文心一言", false)]
  36. static void WenChuangERNIEBotSet()
  37. {
  38. CheckType();
  39. BlueUserListConfig[1].ERNIEBot = !BlueUserListConfig[1].ERNIEBot;
  40. string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
  41. WriteUserListConfig(jsonData);
  42. Menu.SetChecked("用户/文创/文心一言", BlueUserListConfig[1].ERNIEBot);
  43. }
  44. [MenuItem("用户/凝元/自动定位", false)]
  45. static void NingYuanAutoImmersalSet()
  46. {
  47. CheckType();
  48. BlueUserListConfig[2].Auto = !BlueUserListConfig[2].Auto;
  49. string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
  50. WriteUserListConfig(jsonData);
  51. Menu.SetChecked("用户/凝元/自动定位", BlueUserListConfig[2].Auto);
  52. }
  53. [MenuItem("用户/凝元/文心一言", false)]
  54. static void NingYuanERNIEBotSet()
  55. {
  56. CheckType();
  57. BlueUserListConfig[2].ERNIEBot = !BlueUserListConfig[2].ERNIEBot;
  58. string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
  59. WriteUserListConfig(jsonData);
  60. Menu.SetChecked("用户/凝元/文心一言", BlueUserListConfig[2].ERNIEBot);
  61. }
  62. [MenuItem("用户/杨浦党建/自动定位", false)]
  63. static void YangPuDangJianAutoImmersalSet()
  64. {
  65. CheckType();
  66. BlueUserListConfig[3].Auto = !BlueUserListConfig[3].Auto;
  67. string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
  68. WriteUserListConfig(jsonData);
  69. Menu.SetChecked("用户/杨浦党建/自动定位", BlueUserListConfig[3].Auto);
  70. }
  71. [MenuItem("用户/杨浦党建/文心一言", false)]
  72. static void YangPuDangJianERNIEBotSet()
  73. {
  74. CheckType();
  75. BlueUserListConfig[3].ERNIEBot = !BlueUserListConfig[3].ERNIEBot;
  76. string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
  77. WriteUserListConfig(jsonData);
  78. Menu.SetChecked("用户/杨浦党建/文心一言", BlueUserListConfig[3].ERNIEBot);
  79. }
  80. private static void WriteUserListConfig(string UserName)
  81. {
  82. string folderPath = Application.dataPath + "/StreamingAssets";
  83. string filePath = Application.dataPath + "/StreamingAssets" + "/BlueUserListConfig.txt";
  84. if (!Directory.Exists(folderPath))
  85. Directory.CreateDirectory(folderPath);
  86. if (File.Exists(filePath))
  87. File.WriteAllText(filePath, UserName);
  88. else
  89. {
  90. FileStream file = new FileStream(filePath, FileMode.Create);
  91. byte[] bts = System.Text.Encoding.UTF8.GetBytes(UserName);
  92. file.Write(bts, 0, bts.Length);
  93. if (file != null)
  94. {
  95. file.Flush();
  96. file.Close();
  97. file.Dispose();
  98. }
  99. }
  100. AssetDatabase.Refresh();
  101. }
  102. private static BlueUserConfig mBlueUserConfig;
  103. private static void WriteUserConfig(BlueUserType blueUserType)
  104. {
  105. string filePath = Application.dataPath + "/StreamingAssets" + "/BlueUserConfig.txt";
  106. string filePathList = Application.dataPath + "/StreamingAssets" + "/BlueUserListConfig.txt";
  107. string jsonString = File.ReadAllText(filePathList);
  108. List<BlueUserConfig> BlueUserListConfig = JsonConvert.DeserializeObject<List<BlueUserConfig>>(jsonString);
  109. foreach(var BlueUserConfig in BlueUserListConfig)
  110. {
  111. if(BlueUserConfig.BlueUserType==blueUserType.ToString())
  112. {
  113. mBlueUserConfig = new BlueUserConfig()
  114. {
  115. BlueUserType = blueUserType.ToString(),
  116. Auto = BlueUserConfig.Auto,
  117. ERNIEBot = BlueUserConfig.ERNIEBot
  118. };
  119. }
  120. }
  121. string jsonData = JsonConvert.SerializeObject(mBlueUserConfig);
  122. if (File.Exists(filePath))
  123. File.WriteAllText(filePath, jsonData);
  124. else
  125. {
  126. FileStream file = new FileStream(filePath, FileMode.Create);
  127. byte[] bts = System.Text.Encoding.UTF8.GetBytes(jsonData);
  128. file.Write(bts, 0, bts.Length);
  129. if (file != null)
  130. {
  131. file.Flush();
  132. file.Close();
  133. file.Dispose();
  134. }
  135. }
  136. AssetDatabase.Refresh();
  137. }
  138. private static List<BlueUserConfig> BlueUserListConfig;
  139. private static void CheckType()
  140. {
  141. TextAsset jsonTextAsset = Resources.Load("BlueUserListConfig") as TextAsset;
  142. if (jsonTextAsset != null)
  143. BlueUserListConfig = JsonConvert.DeserializeObject<List<BlueUserConfig>>(jsonTextAsset.text);
  144. else
  145. {
  146. var mBlueUserConfig = new BlueUserConfig()
  147. {
  148. BlueUserType = BlueUserType.Blue.ToString(),
  149. Auto = false,
  150. ERNIEBot = false
  151. };
  152. var mWCUserConfig = new BlueUserConfig()
  153. {
  154. BlueUserType = BlueUserType.WenChuang.ToString(),
  155. Auto = false,
  156. ERNIEBot = false
  157. };
  158. var mNYUserConfig = new BlueUserConfig()
  159. {
  160. BlueUserType = BlueUserType.NingYuan.ToString(),
  161. Auto = false,
  162. ERNIEBot = false
  163. };
  164. var mYPDJUserConfig = new BlueUserConfig()
  165. {
  166. BlueUserType = BlueUserType.YangPuDangJian.ToString(),
  167. Auto = false,
  168. ERNIEBot = false
  169. };
  170. BlueUserListConfig = new List<BlueUserConfig>()
  171. {
  172. mBlueUserConfig, // Blue
  173. mWCUserConfig, //文创
  174. mNYUserConfig, //凝元
  175. mYPDJUserConfig}; //杨浦党建
  176. }
  177. }
  178. #region
  179. private static BlueUserType BlueUserType = BlueUserType.DefaultUser;
  180. [MenuItem("用户/选择用户/Blue", false)]
  181. public static void SelectUserBlue()
  182. {
  183. BlueUserType = BlueUserType.Blue;
  184. Active();
  185. WriteUserConfig(BlueUserType.Blue);
  186. }
  187. [MenuItem("用户/选择用户/文创", false)]
  188. public static void SelectUserWC()
  189. {
  190. BlueUserType = BlueUserType.WenChuang;
  191. Active();
  192. WriteUserConfig(BlueUserType.WenChuang);
  193. }
  194. [MenuItem("用户/选择用户/凝元", false)]
  195. public static void SelectUserNY()
  196. {
  197. BlueUserType = BlueUserType.NingYuan;
  198. Active();
  199. WriteUserConfig(BlueUserType.NingYuan);
  200. }
  201. [MenuItem("用户/选择用户/杨浦党建", false)]
  202. public static void SelectUserYPDJ()
  203. {
  204. BlueUserType = BlueUserType.YangPuDangJian;
  205. Active();
  206. WriteUserConfig(BlueUserType.YangPuDangJian);
  207. }
  208. private static void Active()
  209. {
  210. Menu.SetChecked("用户/选择用户/Blue", BlueUserType == BlueUserType.Blue);
  211. Menu.SetChecked("用户/选择用户/文创", BlueUserType == BlueUserType.WenChuang);
  212. Menu.SetChecked("用户/选择用户/凝元", BlueUserType == BlueUserType.NingYuan);
  213. Menu.SetChecked("用户/选择用户/杨浦党建", BlueUserType == BlueUserType.YangPuDangJian);
  214. }
  215. #endregion
  216. }