using System; using System.Collections.Generic; using System.Linq; using System.Text; using Explorer.Unstrip.ColorUtility; using ExplorerBeta.Input; using ExplorerBeta.Unstrip.Resources; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; #if CPP using UnhollowerRuntimeLib; #endif namespace ExplorerBeta.UI.Main { public class DebugConsole { public static DebugConsole Instance { get; private set; } public static bool LogUnity { get; set; } = true; public static GameObject CanvasRoot; public readonly List AllMessages; public readonly List MessageHolders; private TMP_InputField m_textInput; public DebugConsole(GameObject parent) { Instance = this; AllMessages = new List(); MessageHolders = new List(); try { ConstructUI(parent); } catch (Exception e) { ExplorerCore.Log(e); } } // todo: get scrollbar working with inputfield somehow public void ConstructUI(GameObject parent) { var mainObj = UIFactory.CreateVerticalGroup(parent, new Color(0.1f, 0.1f, 0.1f, 1.0f)); var mainGroup = mainObj.GetComponent(); mainGroup.childControlHeight = true; mainGroup.childControlWidth = true; mainGroup.childForceExpandHeight = true; mainGroup.childForceExpandWidth = true; var mainImage = mainObj.GetComponent(); mainImage.maskable = true; var mask = mainObj.AddComponent(); mask.showMaskGraphic = true; var mainLayout = mainObj.AddComponent(); mainLayout.minHeight = 40; mainLayout.preferredHeight = 230; mainLayout.flexibleHeight = 0; #region LOG AREA var logAreaObj = UIFactory.CreateHorizontalGroup(mainObj); var logAreaGroup = logAreaObj.GetComponent(); logAreaGroup.childControlHeight = true; logAreaGroup.childControlWidth = true; logAreaGroup.childForceExpandHeight = true; logAreaGroup.childForceExpandWidth = true; var logAreaLayout = logAreaObj.AddComponent(); logAreaLayout.preferredHeight = 300; logAreaLayout.flexibleHeight = 50; var inputObj = UIFactory.CreateTMPInput(logAreaObj); var mainInputGroup = inputObj.GetComponent(); mainInputGroup.padding.left = 8; mainInputGroup.padding.right = 8; mainInputGroup.padding.top = 5; mainInputGroup.padding.bottom = 5; var inputLayout = inputObj.AddComponent(); inputLayout.preferredWidth = 500; inputLayout.flexibleWidth = 9999; var inputImage = inputObj.GetComponent(); inputImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f); var scroll = UIFactory.CreateScrollbar(logAreaObj); var scrollLayout = scroll.AddComponent(); scrollLayout.preferredWidth = 25; scrollLayout.flexibleWidth = 0; var scroller = scroll.GetComponent(); scroller.direction = Scrollbar.Direction.TopToBottom; var scrollColors = scroller.colors; scrollColors.normalColor = new Color(0.5f, 0.5f, 0.5f, 1.0f); scroller.colors = scrollColors; var tmpInput = inputObj.GetComponent(); tmpInput.scrollSensitivity = 15; tmpInput.verticalScrollbar = scroller; tmpInput.readOnly = true; m_textInput = inputObj.GetComponent(); #endregion #region BOTTOM BAR var bottomBarObj = UIFactory.CreateHorizontalGroup(mainObj); var topBarLayout = bottomBarObj.AddComponent(); topBarLayout.minHeight = 40; topBarLayout.flexibleHeight = 0; var bottomGroup = bottomBarObj.GetComponent(); bottomGroup.padding.left = 10; bottomGroup.padding.right = 10; bottomGroup.padding.top = 2; bottomGroup.padding.bottom = 2; bottomGroup.spacing = 10; bottomGroup.childForceExpandHeight = true; bottomGroup.childForceExpandWidth = false; bottomGroup.childControlWidth = true; bottomGroup.childControlHeight = true; bottomGroup.childAlignment = TextAnchor.MiddleLeft; // Debug Console label var bottomLabel = UIFactory.CreateLabel(bottomBarObj, TextAnchor.MiddleLeft); var topBarLabelLayout = bottomLabel.AddComponent(); topBarLabelLayout.minWidth = 100; topBarLabelLayout.flexibleWidth = 0; var topBarText = bottomLabel.GetComponent(); topBarText.fontStyle = FontStyle.Bold; topBarText.text = "Debug Console"; topBarText.fontSize = 14; // Hide button var hideButtonObj = UIFactory.CreateButton(bottomBarObj); var hideBtnText = hideButtonObj.GetComponentInChildren(); hideBtnText.text = "Hide"; var hideButton = hideButtonObj.GetComponent