123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using System.Collections.Generic;
- using System.IO;
- using Newtonsoft.Json;
- using UnityEditor;
- using UnityEngine;
- public static class EditorUser
- {
- [MenuItem("用户/Blue/自动定位", false)]
- static void BlueAutoImmersalSet()
- {
- CheckType();
- BlueUserListConfig[0].Auto = !BlueUserListConfig[0].Auto;
- string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
- WriteUserListConfig(jsonData);
- Menu.SetChecked("用户/Blue/自动定位", BlueUserListConfig[0].Auto);
- }
- [MenuItem("用户/Blue/文心一言", false)]
- static void BlueERNIEBotSet()
- {
- CheckType();
- BlueUserListConfig[0].ERNIEBot = !BlueUserListConfig[0].ERNIEBot;
- string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
- WriteUserListConfig(jsonData);
- Menu.SetChecked("用户/Blue/文心一言", BlueUserListConfig[0].ERNIEBot);
- }
- [MenuItem("用户/文创/自动定位", false)]
- static void WenChuangAutoImmersalSet()
- {
- CheckType();
- BlueUserListConfig[1].Auto = !BlueUserListConfig[1].Auto;
- string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
- WriteUserListConfig(jsonData);
- Menu.SetChecked("用户/文创/自动定位", BlueUserListConfig[1].Auto);
- }
- [MenuItem("用户/文创/文心一言", false)]
- static void WenChuangERNIEBotSet()
- {
- CheckType();
- BlueUserListConfig[1].ERNIEBot = !BlueUserListConfig[1].ERNIEBot;
- string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
- WriteUserListConfig(jsonData);
- Menu.SetChecked("用户/文创/文心一言", BlueUserListConfig[1].ERNIEBot);
- }
- [MenuItem("用户/凝元/自动定位", false)]
- static void NingYuanAutoImmersalSet()
- {
- CheckType();
- BlueUserListConfig[2].Auto = !BlueUserListConfig[2].Auto;
- string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
- WriteUserListConfig(jsonData);
- Menu.SetChecked("用户/凝元/自动定位", BlueUserListConfig[2].Auto);
- }
- [MenuItem("用户/凝元/文心一言", false)]
- static void NingYuanERNIEBotSet()
- {
- CheckType();
- BlueUserListConfig[2].ERNIEBot = !BlueUserListConfig[2].ERNIEBot;
- string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
- WriteUserListConfig(jsonData);
- Menu.SetChecked("用户/凝元/文心一言", BlueUserListConfig[2].ERNIEBot);
- }
- [MenuItem("用户/杨浦党建/自动定位", false)]
- static void YangPuDangJianAutoImmersalSet()
- {
- CheckType();
- BlueUserListConfig[3].Auto = !BlueUserListConfig[3].Auto;
- string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
- WriteUserListConfig(jsonData);
- Menu.SetChecked("用户/杨浦党建/自动定位", BlueUserListConfig[3].Auto);
- }
- [MenuItem("用户/杨浦党建/文心一言", false)]
- static void YangPuDangJianERNIEBotSet()
- {
- CheckType();
- BlueUserListConfig[3].ERNIEBot = !BlueUserListConfig[3].ERNIEBot;
- string jsonData = JsonConvert.SerializeObject(BlueUserListConfig);
- WriteUserListConfig(jsonData);
- Menu.SetChecked("用户/杨浦党建/文心一言", BlueUserListConfig[3].ERNIEBot);
- }
- private static void WriteUserListConfig(string UserName)
- {
- string folderPath = Application.dataPath + "/Resources";
- string filePath = folderPath + "/BlueUserListConfig.txt";
- if (!Directory.Exists(folderPath))
- Directory.CreateDirectory(folderPath);
- if (File.Exists(filePath))
- File.WriteAllText(filePath, UserName);
- else
- {
- FileStream file = new FileStream(filePath, FileMode.Create);
- byte[] bts = System.Text.Encoding.UTF8.GetBytes(UserName);
- file.Write(bts, 0, bts.Length);
- if (file != null)
- {
- file.Flush();
- file.Close();
- file.Dispose();
- }
- }
- AssetDatabase.Refresh();
- }
- private static BlueUserConfig mBlueUserConfig;
- private static void WriteUserConfig(BlueUserType blueUserType)
- {
- string filePathRes = Application.dataPath + "/Resources" + "/BlueUserConfig.txt";
- string filePathStr = Application.dataPath + "/StreamingAssets" + "/BlueUserConfig.txt";
- string filePathList = Application.dataPath + "/Resources" + "/BlueUserListConfig.txt";
- string jsonString = Resources.Load<TextAsset>("BlueUserListConfig").text;
- List<BlueUserConfig> BlueUserListConfig = JsonConvert.DeserializeObject<List<BlueUserConfig>>(jsonString);
- foreach(var BlueUserConfig in BlueUserListConfig)
- {
- if(BlueUserConfig.BlueUserType==blueUserType.ToString())
- {
- mBlueUserConfig = new BlueUserConfig()
- {
- BlueUserType = blueUserType.ToString(),
- Auto = BlueUserConfig.Auto,
- ERNIEBot = BlueUserConfig.ERNIEBot
- };
- }
- }
- string jsonData = JsonConvert.SerializeObject(mBlueUserConfig);
- if (File.Exists(filePathRes))
- File.WriteAllText(filePathRes, jsonData);
- else
- {
- FileStream file = new FileStream(filePathRes, FileMode.Create);
- byte[] bts = System.Text.Encoding.UTF8.GetBytes(jsonData);
- file.Write(bts, 0, bts.Length);
- if (file != null)
- {
- file.Flush();
- file.Close();
- file.Dispose();
- }
- }
- if (File.Exists(filePathStr))
- File.WriteAllText(filePathStr, jsonData);
- else
- {
- FileStream file = new FileStream(filePathStr, FileMode.Create);
- byte[] bts = System.Text.Encoding.UTF8.GetBytes(jsonData);
- file.Write(bts, 0, bts.Length);
- if (file != null)
- {
- file.Flush();
- file.Close();
- file.Dispose();
- }
- }
- AssetDatabase.Refresh();
- }
- private static List<BlueUserConfig> BlueUserListConfig;
- private static void CheckType()
- {
- TextAsset jsonTextAsset = Resources.Load("BlueUserListConfig") as TextAsset;
- if (jsonTextAsset != null)
- BlueUserListConfig = JsonConvert.DeserializeObject<List<BlueUserConfig>>(jsonTextAsset.text);
- else
- {
- var mBlueUserConfig = new BlueUserConfig()
- {
- BlueUserType = BlueUserType.Blue.ToString(),
- Auto = false,
- ERNIEBot = false
- };
- var mWCUserConfig = new BlueUserConfig()
- {
- BlueUserType = BlueUserType.WenChuang.ToString(),
- Auto = false,
- ERNIEBot = false
- };
- var mNYUserConfig = new BlueUserConfig()
- {
- BlueUserType = BlueUserType.NingYuan.ToString(),
- Auto = false,
- ERNIEBot = false
- };
- var mYPDJUserConfig = new BlueUserConfig()
- {
- BlueUserType = BlueUserType.YangPuDangJian.ToString(),
- Auto = false,
- ERNIEBot = false
- };
- BlueUserListConfig = new List<BlueUserConfig>()
- {
- mBlueUserConfig, // Blue
- mWCUserConfig, //文创
- mNYUserConfig, //凝元
- mYPDJUserConfig}; //杨浦党建
- }
- }
- #region
- private static BlueUserType BlueUserType = BlueUserType.DefaultUser;
- [MenuItem("用户/选择用户/Blue", false)]
- public static void SelectUserBlue()
- {
- BlueUserType = BlueUserType.Blue;
- Active();
- WriteUserConfig(BlueUserType.Blue);
- }
- [MenuItem("用户/选择用户/文创", false)]
- public static void SelectUserWC()
- {
- BlueUserType = BlueUserType.WenChuang;
- Active();
- WriteUserConfig(BlueUserType.WenChuang);
- }
- [MenuItem("用户/选择用户/凝元", false)]
- public static void SelectUserNY()
- {
- BlueUserType = BlueUserType.NingYuan;
- Active();
- WriteUserConfig(BlueUserType.NingYuan);
- }
- [MenuItem("用户/选择用户/杨浦党建", false)]
- public static void SelectUserYPDJ()
- {
- BlueUserType = BlueUserType.YangPuDangJian;
- Active();
- WriteUserConfig(BlueUserType.YangPuDangJian);
- }
- private static void Active()
- {
- Menu.SetChecked("用户/选择用户/Blue", BlueUserType == BlueUserType.Blue);
- Menu.SetChecked("用户/选择用户/文创", BlueUserType == BlueUserType.WenChuang);
- Menu.SetChecked("用户/选择用户/凝元", BlueUserType == BlueUserType.NingYuan);
- Menu.SetChecked("用户/选择用户/杨浦党建", BlueUserType == BlueUserType.YangPuDangJian);
- }
- #endregion
- }
|