mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-03 20:12:33 +08:00
Redesign mouse inspector class, add UI results panel
This commit is contained in:
76
src/UI/Panels/UiInspectorResultsPanel.cs
Normal file
76
src/UI/Panels/UiInspectorResultsPanel.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Inspectors.MouseInspectors;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
|
||||
namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
public class UiInspectorResultsPanel : UIPanel
|
||||
{
|
||||
public override UIManager.Panels PanelType => UIManager.Panels.UIInspectorResults;
|
||||
|
||||
public override string Name => "UI Inspector Results";
|
||||
|
||||
public override int MinWidth => 500;
|
||||
public override int MinHeight => 500;
|
||||
public override bool CanDragAndResize => true;
|
||||
public override bool NavButtonWanted => false;
|
||||
public override bool ShouldSaveActiveState => false;
|
||||
public override bool ShowByDefault => false;
|
||||
|
||||
private ButtonListHandler<GameObject, ButtonCell> dataHandler;
|
||||
private ScrollPool<ButtonCell> buttonScrollPool;
|
||||
|
||||
public override void ConstructPanelContent()
|
||||
{
|
||||
dataHandler = new ButtonListHandler<GameObject, ButtonCell>(buttonScrollPool, GetEntries, SetCell, ShouldDisplayCell, OnCellClicked);
|
||||
|
||||
buttonScrollPool = UIFactory.CreateScrollPool<ButtonCell>(this.content, "ResultsList", out GameObject scrollObj,
|
||||
out GameObject scrollContent);
|
||||
|
||||
buttonScrollPool.Initialize(dataHandler);
|
||||
UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999);
|
||||
}
|
||||
|
||||
public void ShowResults()
|
||||
{
|
||||
dataHandler.RefreshData();
|
||||
buttonScrollPool.Refresh(true, true);
|
||||
}
|
||||
|
||||
private List<GameObject> GetEntries() => UiInspector.LastHitObjects;
|
||||
|
||||
private bool ShouldDisplayCell(object cell, string filter) => true;
|
||||
|
||||
private void OnCellClicked(int index)
|
||||
{
|
||||
if (index >= UiInspector.LastHitObjects.Count)
|
||||
return;
|
||||
|
||||
InspectorManager.Inspect(UiInspector.LastHitObjects[index]);
|
||||
}
|
||||
|
||||
private void SetCell(ButtonCell cell, int index)
|
||||
{
|
||||
if (index >= UiInspector.LastHitObjects.Count)
|
||||
return;
|
||||
|
||||
var obj = UiInspector.LastHitObjects[index];
|
||||
cell.Button.ButtonText.text = $"<color=cyan>{obj.name}</color> ({obj.transform.GetTransformPath(true)})";
|
||||
}
|
||||
|
||||
protected internal override void DoSetDefaultPosAndAnchors()
|
||||
{
|
||||
this.Rect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
this.Rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
this.Rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 500f);
|
||||
this.Rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 500f);
|
||||
}
|
||||
|
||||
public override void DoSaveToConfigElement() { }
|
||||
public override string GetSaveDataFromConfigManager() => null;
|
||||
}
|
||||
}
|
@ -27,7 +27,8 @@ namespace UnityExplorer.UI
|
||||
Options,
|
||||
ConsoleLog,
|
||||
AutoCompleter,
|
||||
MouseInspector
|
||||
MouseInspector,
|
||||
UIInspectorResults,
|
||||
}
|
||||
|
||||
public enum VerticalAnchor
|
||||
@ -108,6 +109,7 @@ namespace UnityExplorer.UI
|
||||
UIPanels.Add(Panels.CSConsole, new CSConsolePanel());
|
||||
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
|
||||
UIPanels.Add(Panels.Options, new OptionsPanel());
|
||||
UIPanels.Add(Panels.UIInspectorResults, new UiInspectorResultsPanel());
|
||||
UIPanels.Add(Panels.MouseInspector, new InspectUnderMouse());
|
||||
|
||||
foreach (var panel in UIPanels.Values)
|
||||
|
Reference in New Issue
Block a user