EditorUser.cs 8.2 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 + "/Resources";
  83. string filePath = Application.dataPath + "/Resources" + "/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 + "/Resources" + "/BlueUserConfig.txt";
  106. TextAsset jsonTextAsset = Resources.Load("BlueUserListConfig") as TextAsset;
  107. List<BlueUserConfig> BlueUserListConfig = JsonConvert.DeserializeObject<List<BlueUserConfig>>(jsonTextAsset.text);
  108. foreach(var BlueUserConfig in BlueUserListConfig)
  109. {
  110. if(BlueUserConfig.BlueUserType==blueUserType.ToString())
  111. {
  112. mBlueUserConfig = new BlueUserConfig()
  113. {
  114. BlueUserType = blueUserType.ToString(),
  115. Auto = BlueUserConfig.Auto,
  116. ERNIEBot = BlueUserConfig.ERNIEBot
  117. };
  118. }
  119. }
  120. string jsonData = JsonConvert.SerializeObject(mBlueUserConfig);
  121. if (File.Exists(filePath))
  122. File.WriteAllText(filePath, jsonData);
  123. else
  124. {
  125. FileStream file = new FileStream(filePath, FileMode.Create);
  126. byte[] bts = System.Text.Encoding.UTF8.GetBytes(jsonData);
  127. file.Write(bts, 0, bts.Length);
  128. if (file != null)
  129. {
  130. file.Flush();
  131. file.Close();
  132. file.Dispose();
  133. }
  134. }
  135. AssetDatabase.Refresh();
  136. }
  137. private static List<BlueUserConfig> BlueUserListConfig;
  138. private static void CheckType()
  139. {
  140. TextAsset jsonTextAsset = Resources.Load("BlueUserListConfig") as TextAsset;
  141. if (jsonTextAsset != null)
  142. BlueUserListConfig = JsonConvert.DeserializeObject<List<BlueUserConfig>>(jsonTextAsset.text);
  143. else
  144. {
  145. var mBlueUserConfig = new BlueUserConfig()
  146. {
  147. BlueUserType = BlueUserType.Blue.ToString(),
  148. Auto = false,
  149. ERNIEBot = false
  150. };
  151. var mWCUserConfig = new BlueUserConfig()
  152. {
  153. BlueUserType = BlueUserType.WenChuang.ToString(),
  154. Auto = false,
  155. ERNIEBot = false
  156. };
  157. var mNYUserConfig = new BlueUserConfig()
  158. {
  159. BlueUserType = BlueUserType.NingYuan.ToString(),
  160. Auto = false,
  161. ERNIEBot = false
  162. };
  163. var mYPDJUserConfig = new BlueUserConfig()
  164. {
  165. BlueUserType = BlueUserType.YangPuDangJian.ToString(),
  166. Auto = false,
  167. ERNIEBot = false
  168. };
  169. BlueUserListConfig = new List<BlueUserConfig>()
  170. {
  171. mBlueUserConfig, // Blue
  172. mWCUserConfig, //文创
  173. mNYUserConfig, //凝元
  174. mYPDJUserConfig}; //杨浦党建
  175. }
  176. }
  177. #region
  178. private static BlueUserType BlueUserType = BlueUserType.DefaultUser;
  179. [MenuItem("用户/选择用户/Blue", false)]
  180. public static void SelectUserBlue()
  181. {
  182. BlueUserType = BlueUserType.Blue;
  183. Active();
  184. WriteUserConfig(BlueUserType.Blue);
  185. }
  186. [MenuItem("用户/选择用户/文创", false)]
  187. public static void SelectUserWC()
  188. {
  189. BlueUserType = BlueUserType.WenChuang;
  190. Active();
  191. WriteUserConfig(BlueUserType.WenChuang);
  192. }
  193. [MenuItem("用户/选择用户/凝元", false)]
  194. public static void SelectUserNY()
  195. {
  196. BlueUserType = BlueUserType.NingYuan;
  197. Active();
  198. WriteUserConfig(BlueUserType.NingYuan);
  199. }
  200. [MenuItem("用户/选择用户/杨浦党建", false)]
  201. public static void SelectUserYPDJ()
  202. {
  203. BlueUserType = BlueUserType.YangPuDangJian;
  204. Active();
  205. WriteUserConfig(BlueUserType.YangPuDangJian);
  206. }
  207. private static void Active()
  208. {
  209. Menu.SetChecked("用户/选择用户/Blue", BlueUserType == BlueUserType.Blue);
  210. Menu.SetChecked("用户/选择用户/文创", BlueUserType == BlueUserType.WenChuang);
  211. Menu.SetChecked("用户/选择用户/凝元", BlueUserType == BlueUserType.NingYuan);
  212. Menu.SetChecked("用户/选择用户/杨浦党建", BlueUserType == BlueUserType.YangPuDangJian);
  213. }
  214. #endregion
  215. }