using System.Collections.Generic; using System.Text; using SRDebugger.Services; using SRDebugger.UI.Controls; using SRF; using SRF.Service; using UnityEngine; namespace SRDebugger.UI.Tabs { public class InfoTabController : SRMonoBehaviourEx { public const char Tick = '✓'; public const char Cross = '×'; public const string NameColor = "#BCBCBC"; private Dictionary _infoBlocks = new Dictionary(); [RequiredField] public InfoBlock InfoBlockPrefab; [RequiredField] public RectTransform LayoutContainer; protected override void Start() { base.Start(); Construct(); } protected override void OnEnable() { base.OnEnable(); Refresh(); } public void Refresh() { ISystemInformationService service = SRServiceManager.GetService(); foreach (KeyValuePair infoBlock in _infoBlocks) { FillInfoBlock(infoBlock.Value, service.GetInfo(infoBlock.Key)); } } private void Construct() { ISystemInformationService service = SRServiceManager.GetService(); foreach (string category in service.GetCategories()) { IList info = service.GetInfo(category); if (info.Count != 0) { InfoBlock infoBlock = CreateBlock(category); FillInfoBlock(infoBlock, info); _infoBlocks.Add(category, infoBlock); } } } private void FillInfoBlock(InfoBlock block, IList info) { StringBuilder stringBuilder = new StringBuilder(); int num = 0; foreach (ISystemInfo item in info) { if (item.Title.Length > num) { num = item.Title.Length; } } num += 2; bool flag = true; foreach (ISystemInfo item2 in info) { if (flag) { flag = false; } else { stringBuilder.AppendLine(); } stringBuilder.Append(""); stringBuilder.Append(item2.Title); stringBuilder.Append(": "); stringBuilder.Append(""); for (int i = item2.Title.Length; i <= num; i++) { stringBuilder.Append(' '); } if (item2.Value is bool) { stringBuilder.Append((!(bool)item2.Value) ? '×' : '✓'); } else { stringBuilder.Append(item2.Value); } } block.Content.text = stringBuilder.ToString(); } private InfoBlock CreateBlock(string title) { InfoBlock infoBlock = SRInstantiate.Instantiate(InfoBlockPrefab); infoBlock.Title.text = title; infoBlock.CachedTransform.SetParent(LayoutContainer, false); return infoBlock; } } }