public ConsoleInfo[] Load() { var consoleInfos = new List <ConsoleInfo>(); var configJson = Prefs.config; if (!string.IsNullOrEmpty(configJson)) { var infos = JsonConvert.DeserializeObject <ConsoleInfo[]>(configJson); consoleInfos = infos.ToList(); } if (consoleInfos.IsEmpty()) { var info = new ConsoleInfo() { eventName = UnityConsole.InfoEvent.ConsoleEventName, enable = true, }; consoleInfos.Add(info); } ConsoleInfos = consoleInfos; return(ConsoleInfos.ToArray()); }
private void SetupDefaultInfos() { var config = UnityConsoleConfig.Instance; if (config == null) { return; } var unityConsoleManager = UnityConsoleManager.Instance; var definedInfos = config.GetDefinedInfos(); var hasChange = false; foreach (var info in definedInfos) { if (consoleInfos.Any(x => x.eventName == info.eventName)) { continue; } var newInfo = new ConsoleInfo() { eventName = info.eventName, enable = info.enable, }; consoleInfos.Add(newInfo); hasChange = true; } if (hasChange) { unityConsoleManager.Save(consoleInfos); } }
void OnGUI() { var unityConsoleManager = UnityConsoleManager.Instance; EditorGUILayout.Separator(); var isEnable = unityConsoleManager.IsEnable(); EditorGUI.BeginChangeCheck(); isEnable = EditorGUILayout.Toggle("UnityConsole Enable", isEnable); if (EditorGUI.EndChangeCheck()) { unityConsoleManager.SetEnable(isEnable); } GUILayout.Space(2f); using (new ContentsScope()) { using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosition)) { var removeList = new List <ConsoleInfo>(); foreach (var consoleInfo in consoleInfos) { using (new EditorGUILayout.HorizontalScope()) { using (new DisableScope(consoleInfo.eventName == UnityConsole.InfoEvent.ConsoleEventName)) { consoleInfo.eventName = EditorGUILayout.DelayedTextField(consoleInfo.eventName); } GUILayout.Space(5f); using (new LabelWidthScope(0f)) { consoleInfo.enable = EditorGUILayout.Toggle(consoleInfo.enable, GUILayout.Width(18f)); } var disableDelete = false; disableDelete |= consoleInfo.eventName == UnityConsole.InfoEvent.ConsoleEventName; disableDelete |= IsDefinedInfo(consoleInfo.eventName); using (new DisableScope(disableDelete)) { if (GUILayout.Button("-", GUILayout.Height(18f))) { removeList.Add(consoleInfo); } } } } foreach (var item in removeList) { consoleInfos.Remove(item); } scrollPosition = scrollViewScope.scrollPosition; } } using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("+")) { var newInfo = new ConsoleInfo() { eventName = string.Empty, enable = true, }; consoleInfos.Add(newInfo); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Save")) { unityConsoleManager.Save(consoleInfos); } } }