using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; using BITKit; using BITKit.UX; using System.Linq; using UnityEngine.InputSystem; using Cysharp.Threading.Tasks; using System.Text; using System.IO; using System.Reflection; using System.Reflection.Emit; using BITKit.Mod; using UnityEngine.InputSystem.Interactions; using Label = UnityEngine.UIElements.Label; using Object = UnityEngine.Object; // ReSharper disable PossibleMultipleEnumeration namespace BITKit.Console { public class UXConsole:IDisposable { [BITCommand] // ReSharper disable once UnusedMember.Global public static void Console_Exception_Print_StackTrace(int allow) { _exceptionPrintStackTrace = allow is 1; } private readonly IMainTicker _ticker; public UXConsole(IMainTicker ticker) { _ticker = ticker; _singleton = this; _ticker.Add(OnTick); InitializeAsync(); Application.logMessageReceivedThreaded += EnqueueLog; } private async void InitializeAsync() { var go = new GameObject("UXConsole"); Object.DontDestroyOnLoad(go); var document = go.AddComponent(); document.sortingOrder = 1; try { var panelSettings =await ModService.LoadAsset("ux_panel_settings"); document.panelSettings = panelSettings; } catch (Exception e) { BIT4Log.Warning("未找到ux_panel_settings"); throw; } document.visualTreeAsset = await ModService.LoadAsset("ui_console"); _rootVisualElement = document.rootVisualElement; UXUtils.Inject(this,_rootVisualElement); _commandSelector = new() { Container = _commandContainer, }; _commandSelector.OnSelected += x => { _textField.SetValueWithoutNotify(x.Name); _textField.Blur(); _textField.Focus(); }; _singleton = this; _textField.RegisterValueChangedCallback(OnTextFieldValueChanged); _textField.RegisterCallback(OnKeyDown); _text.text = string.Empty; Toggle(false); } private VisualElement _rootVisualElement; private static bool _exceptionPrintStackTrace; private class CommandSelector { public VisualElement Container { get; set; } public int Index { get => _index; set { if (_methods.Length is 0) { _index = -1; return; } _index = (value+_methods.Length)%_methods.Length; Rebuild(); } } public event Action OnSelected; private int _index; private MethodInfo[] _methods=Array.Empty(); public void Rebuild() { Container.Clear(); for (var i = 0; i < _methods.Length; i++) { var method = _methods[i]; var button = Container.Create