BS 0.2.0 Visual

This commit is contained in:
2025-07-21 15:58:52 +08:00
parent f6750189d0
commit d0e5420f95
142 changed files with 11176 additions and 11 deletions

View File

@@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
public class ConsoleListItem : WindowUIModule,IText,ITitle
{
[Resources, SerializeField, OnlyNotNullMode] private Text MyTitleText;
[Resources, SerializeField, OnlyNotNullMode] private Button RawButton;
public string stackTrace;
public bool IsEnableFocusWindow;
public LogType logType;
public string text { get => ((IText)this.MyTitleText).text; set => ((IText)this.MyTitleText).text = value; }
public string title { get => ((ITitle)this.MyTitleText).title; set => ((ITitle)this.MyTitleText).title = value; }
public void SetupMessage(string message, string stackTrace, string color, LogType logType, string format = "<color={color}>{message}</color>")
{
format = format.Replace("{color}", color);
format = format.Replace("{message}", message);
this.title = format;
this.stackTrace = stackTrace;
this.logType = logType;
}
protected void Start()
{
RawButton.onClick.AddListener(OnFocusConsoleItem);
}
[Content]
public void OnFocusConsoleItem()
{
ConsoleWindow.instance.SetStackTrace(this.title + "\n\n" + this.stackTrace);
if (!IsEnableFocusWindow)
return;
if (FocusWindowIndictaor.instance != null)
FocusWindowIndictaor.instance.SetTargetRectTransform(MyTitleText.transform as RectTransform);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec27d0c4063956e4fbe412c7e30f2b3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,153 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
[RequireComponent(typeof(PropertiesWindow))]
public class ConsoleWindow : MonoSingleton<ConsoleWindow>
{
[Resources, SerializeField, OnlyNotNullMode, Header("Bar Button Setting")] private WindowManager m_WindowManager;
[Resources, SerializeField, OnlyNotNullMode(nameof(m_WindowManager))] private RectTransform m_root;
[Resources, SerializeField, OnlyNotNullMode(nameof(m_WindowManager))] private RectTransform m_plane;
public int ConsoleWindowIndex { get; private set; }
[Header("Property Window - ListView"), Resources, SerializeField, OnlyNotNullMode] private PropertiesWindow m_ListView;
private List<PropertiesWindow.ItemEntry> m_entries = new();
[Resources, SerializeField, OnlyNotNullMode] private ModernUIInputField StackTrace;
[Header("Message Switch"), Resources, SerializeField, OnlyNotNullMode] private ModernUIToggle m_MessageSwitch;
[Resources, SerializeField, OnlyNotNullMode] private ModernUIToggle m_WarningSwitch;
[Resources, SerializeField, OnlyNotNullMode] private ModernUIToggle m_VitalSwitch;
[Resources, SerializeField, OnlyNotNullMode] private Button m_ClearLogs;
[Setting] public string ConsoleButtonName = "Console";
public void ClearLog()
{
foreach (var entry in m_entries)
{
entry.Release();
}
m_entries.Clear();
}
public void Log(string condition, string stackTrace, LogType type = LogType.Log)
{
ConsoleListItem item;
string color;
GenerateLogItem(type, out item, out color);
item.SetupMessage(condition, stackTrace, color, type);
}
private void GenerateLogItem(LogType type, out ConsoleListItem item, out string color)
{
bool isActive = type switch
{
LogType.Log => m_MessageSwitch.ref_value,
LogType.Warning => m_WarningSwitch.ref_value,
_ => m_VitalSwitch.ref_value
};
PropertiesWindow.ItemEntry entry = m_ListView.CreateRootItemEntries(isActive, 1)[0];
m_entries.Add(entry);
item = entry.ref_value.GetComponent<ConsoleListItem>();
color = type switch
{
LogType.Log => "white",
LogType.Warning => "yellow",
_ => "red"
};
}
public void Log(string condition, string stackTrace, LogType type, string format)
{
ConsoleListItem item;
string color;
GenerateLogItem(type, out item, out color);
item.SetupMessage(condition, stackTrace, color, type, format);
}
public void SetStackTrace(string str)
{
StackTrace.text = str;
}
private void Start()
{
Application.logMessageReceived -= Log;
Application.logMessageReceived += Log;
ConsoleWindowIndex = m_WindowManager.AddContextPlane(m_plane, m_root);
var buttonWrapper = m_WindowManager.CreateWindowBarButton(() =>
{
m_WindowManager.SelectContextPlane(ConsoleWindowIndex);
});
(buttonWrapper.button as ITitle).title = ConsoleButtonName;
//StackTrace.interactable = false;
StackTrace.InputFieldSource.Source.readOnly = true;
m_MessageSwitch.ref_value = true;
m_WarningSwitch.ref_value = true;
m_VitalSwitch.ref_value = true;
m_MessageSwitch.AddListener(x =>
{
foreach (var entry in m_entries)
{
var item = entry.ref_value.GetComponent<ConsoleListItem>();
if (item.logType == LogType.Log)
{
item.gameObject.SetActive(x);
}
}
});
m_WarningSwitch.AddListener(x =>
{
foreach (var entry in m_entries)
{
var item = entry.ref_value.GetComponent<ConsoleListItem>();
if (item.logType == LogType.Warning)
{
item.gameObject.SetActive(x);
}
}
});
m_VitalSwitch.AddListener(x =>
{
foreach (var entry in m_entries)
{
var item = entry.ref_value.GetComponent<ConsoleListItem>();
if (item.logType != LogType.Log && item.logType != LogType.Warning)
{
item.gameObject.SetActive(x);
}
}
});
m_ClearLogs.onClick.AddListener(() =>
{
foreach (var entry in m_entries)
{
entry.Release();
}
m_entries.Clear();
});
m_WindowManager.SelectContextPlane(0);
}
[Setting, OnlyPlayMode]
public void TestLog()
{
Debug.Log("Test");
}
[Setting, OnlyPlayMode]
public void TestWarning()
{
Debug.LogWarning("Test");
}
[Setting, OnlyPlayMode]
public void TestError()
{
Debug.LogError("Test");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6845a63f12419f14fa03fa95accccfb0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: