mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-06 01:23:31 +08:00
Create preliminary GameObject inspector for testing, cleanup some UI
This commit is contained in:
parent
40d32e1919
commit
085c79441b
128
src/UI/Panels/GameObjectInspector.cs
Normal file
128
src/UI/Panels/GameObjectInspector.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Models;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
|
||||
namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
public class GameObjectInspector : UIPanel
|
||||
{
|
||||
public override string Name => "GameObject Inspector";
|
||||
|
||||
public SimpleListSource<Component> ComponentList;
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<Component> GetEntries()
|
||||
{
|
||||
var comp = Camera.main;
|
||||
return new List<Component>
|
||||
{
|
||||
comp, comp, comp, comp, comp
|
||||
};
|
||||
}
|
||||
|
||||
public SimpleCell<Component> CreateCell(RectTransform rect)
|
||||
{
|
||||
var button = rect.GetComponentInChildren<Button>();
|
||||
var text = button.GetComponentInChildren<Text>();
|
||||
var cell = new SimpleCell<Component>(ComponentList, rect.gameObject, button, text);
|
||||
cell.OnClick += OnCellClicked;
|
||||
return cell;
|
||||
}
|
||||
|
||||
public void OnCellClicked(SimpleCell<Component> cell)
|
||||
{
|
||||
ExplorerCore.Log("Cell clicked!");
|
||||
}
|
||||
|
||||
public void SetCell(SimpleCell<Component> cell, int index)
|
||||
{
|
||||
var comp = ComponentList.currentEntries[index];
|
||||
if (!comp)
|
||||
cell.buttonText.text = "<color=red>[Destroyed]</color>";
|
||||
else
|
||||
cell.buttonText.text = ToStringUtility.GetDefaultLabel(comp, ReflectionProvider.Instance.GetActualType(comp), true, false);
|
||||
}
|
||||
|
||||
public bool ShouldFilter(Component comp, string filter)
|
||||
{
|
||||
return comp.name.ToLower().Contains(filter);
|
||||
}
|
||||
|
||||
public override void LoadSaveData()
|
||||
{
|
||||
ApplySaveData(ConfigManager.GameObjectInspectorData.Value);
|
||||
}
|
||||
|
||||
public override void SaveToConfigManager()
|
||||
{
|
||||
ConfigManager.GameObjectInspectorData.Value = this.ToSaveData();
|
||||
}
|
||||
|
||||
public override void OnFinishResize(RectTransform panel)
|
||||
{
|
||||
base.OnFinishResize(panel);
|
||||
RuntimeProvider.Instance.StartCoroutine(DelayedRefresh(panel));
|
||||
}
|
||||
|
||||
private float previousRectHeight;
|
||||
|
||||
private IEnumerator DelayedRefresh(RectTransform obj)
|
||||
{
|
||||
yield return null;
|
||||
|
||||
if (obj.rect.height != previousRectHeight)
|
||||
{
|
||||
// height changed, hard refresh required.
|
||||
previousRectHeight = obj.rect.height;
|
||||
ComponentList.Scroller.ReloadData();
|
||||
}
|
||||
|
||||
ComponentList.Scroller.Refresh();
|
||||
}
|
||||
|
||||
public override void SetDefaultPosAndAnchors()
|
||||
{
|
||||
mainPanelRect.localPosition = Vector2.zero;
|
||||
mainPanelRect.anchorMin = new Vector2(0.6f, 0.3f);
|
||||
mainPanelRect.anchorMax = new Vector2(0.95f, 0.9f);
|
||||
mainPanelRect.sizeDelta = new Vector2(-300f, mainPanelRect.sizeDelta.y);
|
||||
mainPanelRect.anchoredPosition = new Vector2(-160, 0);
|
||||
mainPanelRect.offsetMin = new Vector2(mainPanelRect.offsetMin.x, 10); // bottom
|
||||
mainPanelRect.offsetMax = new Vector2(mainPanelRect.offsetMax.x, -10); // top
|
||||
mainPanelRect.pivot = new Vector2(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
public override void ConstructPanelContent()
|
||||
{
|
||||
// Transform Tree
|
||||
|
||||
var infiniteScroll = UIFactory.CreateInfiniteScroll(content, "ComponentList", out GameObject scrollObj,
|
||||
out GameObject scrollContent, new Color(0.15f, 0.15f, 0.15f));
|
||||
UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999);
|
||||
UIFactory.SetLayoutElement(scrollContent, flexibleHeight: 9999);
|
||||
|
||||
ComponentList = new SimpleListSource<Component>(infiniteScroll, GetEntries, CreateCell, SetCell, ShouldFilter);
|
||||
ComponentList.Init();
|
||||
|
||||
// Prototype tree cell
|
||||
var prototype = SimpleCell<Component>.CreatePrototypeCell(scrollContent);
|
||||
infiniteScroll.PrototypeCell = prototype.GetComponent<RectTransform>();
|
||||
|
||||
// some references
|
||||
previousRectHeight = mainPanelRect.rect.height;
|
||||
}
|
||||
}
|
||||
}
|
@ -136,11 +136,6 @@ namespace UnityExplorer.UI.Panels
|
||||
RuntimeProvider.Instance.StartCoroutine(DelayedRefresh(panel));
|
||||
}
|
||||
|
||||
public override void SaveToConfigManager()
|
||||
{
|
||||
ConfigManager.SceneExplorerData.Value = this.ToSaveData();
|
||||
}
|
||||
|
||||
private IEnumerator DelayedRefresh(RectTransform obj)
|
||||
{
|
||||
yield return null;
|
||||
@ -152,13 +147,16 @@ namespace UnityExplorer.UI.Panels
|
||||
Tree.Scroller.ReloadData();
|
||||
}
|
||||
Tree.Scroller.Refresh();
|
||||
}
|
||||
|
||||
public override void SaveToConfigManager()
|
||||
{
|
||||
ConfigManager.SceneExplorerData.Value = this.ToSaveData();
|
||||
}
|
||||
|
||||
public override void LoadSaveData()
|
||||
{
|
||||
var data = ConfigManager.SceneExplorerData.Value;
|
||||
ApplySaveData(data);
|
||||
ApplySaveData(ConfigManager.SceneExplorerData.Value);
|
||||
}
|
||||
|
||||
public override void SetDefaultPosAndAnchors()
|
||||
@ -242,7 +240,6 @@ namespace UnityExplorer.UI.Panels
|
||||
infiniteScroll.PrototypeCell = prototype.GetComponent<RectTransform>();
|
||||
|
||||
// some references
|
||||
Tree.Scroller = infiniteScroll;
|
||||
previousRectHeight = mainPanelRect.rect.height;
|
||||
|
||||
// Scene Loader
|
||||
@ -257,7 +254,7 @@ namespace UnityExplorer.UI.Panels
|
||||
UIFactory.SetLayoutElement(allSceneDropObj, minHeight: 25, minWidth: 150, flexibleWidth: 0, flexibleHeight: 0);
|
||||
|
||||
foreach (var scene in SceneHandler.AllSceneNames)
|
||||
allSceneDrop.options.Add(new Dropdown.OptionData(scene));
|
||||
allSceneDrop.options.Add(new Dropdown.OptionData(Path.GetFileNameWithoutExtension(scene)));
|
||||
|
||||
allSceneDrop.value = 1;
|
||||
allSceneDrop.value = 0;
|
||||
|
@ -6,7 +6,6 @@ using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
using UnityExplorer.UI.Widgets.InfiniteScroll;
|
||||
|
||||
namespace UnityExplorer.UI
|
||||
{
|
||||
@ -569,7 +568,7 @@ namespace UnityExplorer.UI
|
||||
|
||||
GameObject scrollbarObj = CreateScrollbar(templateObj, "DropdownScroll", out Scrollbar scrollbar);
|
||||
scrollbar.SetDirection(Scrollbar.Direction.BottomToTop, true);
|
||||
RuntimeProvider.Instance.SetColorBlock(scrollbar, new Color(0.3f, 0.3f, 0.3f), new Color(0.4f, 0.4f, 0.4f), new Color(0.2f, 0.2f, 0.2f));
|
||||
RuntimeProvider.Instance.SetColorBlock(scrollbar, new Color(0.45f, 0.45f, 0.45f), new Color(0.6f, 0.6f, 0.6f), new Color(0.4f, 0.4f, 0.4f));
|
||||
|
||||
RectTransform scrollRectTransform = scrollbarObj.GetComponent<RectTransform>();
|
||||
scrollRectTransform.anchorMin = Vector2.right;
|
||||
@ -593,18 +592,18 @@ namespace UnityExplorer.UI
|
||||
arrowRect.anchoredPosition = new Vector2(-15f, 0f);
|
||||
|
||||
Image itemBgImage = itemBgObj.AddComponent<Image>();
|
||||
itemBgImage.color = new Color(0.25f, 0.45f, 0.25f, 1.0f);
|
||||
itemBgImage.color = new Color(0.25f, 0.35f, 0.25f, 1.0f);
|
||||
|
||||
Toggle itemToggle = itemObj.AddComponent<Toggle>();
|
||||
itemToggle.targetGraphic = itemBgImage;
|
||||
itemToggle.isOn = true;
|
||||
RuntimeProvider.Instance.SetColorBlock(itemToggle,
|
||||
new Color(0.35f, 0.35f, 0.35f, 1.0f), new Color(0.25f, 0.45f, 0.25f, 1.0f));
|
||||
new Color(0.35f, 0.35f, 0.35f, 1.0f), new Color(0.25f, 0.55f, 0.25f, 1.0f));
|
||||
|
||||
itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); });
|
||||
Image templateImage = templateObj.AddComponent<Image>();
|
||||
templateImage.type = Image.Type.Sliced;
|
||||
templateImage.color = new Color(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
templateImage.color = Color.black;
|
||||
|
||||
var scrollRect = templateObj.AddComponent<ScrollRect>();
|
||||
scrollRect.scrollSensitivity = 35;
|
||||
@ -626,7 +625,7 @@ namespace UnityExplorer.UI
|
||||
labelText.alignment = TextAnchor.MiddleLeft;
|
||||
|
||||
Image dropdownImage = dropdownObj.AddComponent<Image>();
|
||||
dropdownImage.color = new Color(0.2f, 0.2f, 0.2f, 1);
|
||||
dropdownImage.color = new Color(0.07f, 0.07f, 0.07f, 1);
|
||||
dropdownImage.type = Image.Type.Sliced;
|
||||
|
||||
dropdown = dropdownObj.AddComponent<Dropdown>();
|
||||
|
@ -12,7 +12,6 @@ using UnityExplorer.UI.Models;
|
||||
using UnityExplorer.UI.Panels;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
using UnityExplorer.UI.Widgets.InfiniteScroll;
|
||||
|
||||
namespace UnityExplorer.UI
|
||||
{
|
||||
@ -23,6 +22,7 @@ namespace UnityExplorer.UI
|
||||
|
||||
// panels
|
||||
public static SceneExplorer SceneExplorer { get; private set; }
|
||||
public static GameObjectInspector GOInspector { get; private set; }
|
||||
|
||||
// bundle assets
|
||||
internal static Font ConsoleFont { get; private set; }
|
||||
@ -54,6 +54,9 @@ namespace UnityExplorer.UI
|
||||
SceneExplorer = new SceneExplorer();
|
||||
SceneExplorer.ConstructUI(CanvasRoot);
|
||||
|
||||
GOInspector = new GameObjectInspector();
|
||||
GOInspector.ConstructUI(CanvasRoot);
|
||||
|
||||
//MainMenu.Create();
|
||||
//InspectUnderMouse.ConstructUI();
|
||||
//PanelDragger.CreateCursorUI();
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets.InfiniteScroll
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
public interface ICell
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets.InfiniteScroll
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
public interface IListDataSource
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Models;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets.InfiniteScroll
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
public class InfiniteScrollRect : UIBehaviourModel
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets.InfiniteScroll
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
public static class UIExtension
|
||||
{
|
||||
|
74
src/UI/Widgets/SimpleList/SimpleCell.cs
Normal file
74
src/UI/Widgets/SimpleList/SimpleCell.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
public class SimpleCell<T> : ICell
|
||||
{
|
||||
public bool Enabled => m_enabled;
|
||||
private bool m_enabled;
|
||||
|
||||
public Action<SimpleCell<T>> OnClick;
|
||||
|
||||
public SimpleListSource<T> list;
|
||||
|
||||
public GameObject uiRoot;
|
||||
public Text buttonText;
|
||||
public Button button;
|
||||
|
||||
public SimpleCell(SimpleListSource<T> list, GameObject uiRoot, Button button, Text text)
|
||||
{
|
||||
this.list = list;
|
||||
this.uiRoot = uiRoot;
|
||||
this.buttonText = text;
|
||||
this.button = button;
|
||||
|
||||
button.onClick.AddListener(() => { OnClick?.Invoke(this); });
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
m_enabled = false;
|
||||
uiRoot.SetActive(false);
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
m_enabled = true;
|
||||
uiRoot.SetActive(true);
|
||||
}
|
||||
|
||||
public static GameObject CreatePrototypeCell(GameObject parent)
|
||||
{
|
||||
var prototype = UIFactory.CreateHorizontalGroup(parent, "PrototypeCell", true, true, true, true, 2, default,
|
||||
new Color(0.15f, 0.15f, 0.15f), TextAnchor.MiddleCenter);
|
||||
//var cell = prototype.AddComponent<TransformCell>();
|
||||
var rect = prototype.GetComponent<RectTransform>();
|
||||
rect.anchorMin = new Vector2(0, 1);
|
||||
rect.anchorMax = new Vector2(0, 1);
|
||||
rect.pivot = new Vector2(0.5f, 1);
|
||||
rect.sizeDelta = new Vector2(25, 25);
|
||||
UIFactory.SetLayoutElement(prototype, minWidth: 100, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
||||
|
||||
var nameButton = UIFactory.CreateButton(prototype, "NameButton", "Name", null);
|
||||
UIFactory.SetLayoutElement(nameButton.gameObject, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
|
||||
var nameLabel = nameButton.GetComponentInChildren<Text>();
|
||||
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
nameLabel.alignment = TextAnchor.MiddleLeft;
|
||||
|
||||
Color normal = new Color(0.15f, 0.15f, 0.15f);
|
||||
Color highlight = new Color(0.25f, 0.25f, 0.25f);
|
||||
Color pressed = new Color(0.05f, 0.05f, 0.05f);
|
||||
Color disabled = new Color(1, 1, 1, 0);
|
||||
RuntimeProvider.Instance.SetColorBlock(nameButton, normal, highlight, pressed, disabled);
|
||||
|
||||
prototype.SetActive(false);
|
||||
|
||||
return prototype;
|
||||
}
|
||||
}
|
||||
}
|
95
src/UI/Widgets/SimpleList/SimpleListSource.cs
Normal file
95
src/UI/Widgets/SimpleList/SimpleListSource.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
public class SimpleListSource<T> : IListDataSource
|
||||
{
|
||||
internal InfiniteScrollRect Scroller;
|
||||
|
||||
public Func<List<T>> GetEntries;
|
||||
public List<T> currentEntries;
|
||||
|
||||
public int ItemCount => currentEntries.Count;
|
||||
|
||||
public Func<RectTransform, SimpleCell<T>> CreateICell;
|
||||
public Action<SimpleCell<T>, int> SetICell;
|
||||
|
||||
public Func<T, string, bool> ShouldFilter;
|
||||
|
||||
public string CurrentFilter
|
||||
{
|
||||
get => currentFilter;
|
||||
set => currentFilter = value?.ToLower() ?? "";
|
||||
}
|
||||
private string currentFilter;
|
||||
|
||||
public SimpleListSource(InfiniteScrollRect infiniteScroller, Func<List<T>> getEntriesMethod,
|
||||
Func<RectTransform, SimpleCell<T>> createCellMethod, Action<SimpleCell<T>, int> setICellMethod,
|
||||
Func<T, string, bool> shouldFilterMethod)
|
||||
{
|
||||
Scroller = infiniteScroller;
|
||||
|
||||
GetEntries = getEntriesMethod;
|
||||
CreateICell = createCellMethod;
|
||||
SetICell = setICellMethod;
|
||||
ShouldFilter = shouldFilterMethod;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
RuntimeProvider.Instance.StartCoroutine(InitCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator InitCoroutine()
|
||||
{
|
||||
yield return null;
|
||||
|
||||
RefreshData();
|
||||
Scroller.DataSource = this;
|
||||
Scroller.Initialize(this);
|
||||
}
|
||||
|
||||
public void RefreshData()
|
||||
{
|
||||
var allEntries = GetEntries.Invoke();
|
||||
var list = new List<T>();
|
||||
|
||||
foreach (var entry in allEntries)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(currentFilter))
|
||||
{
|
||||
if (!ShouldFilter.Invoke(entry, currentFilter))
|
||||
continue;
|
||||
|
||||
list.Add(entry);
|
||||
}
|
||||
else
|
||||
list.Add(entry);
|
||||
}
|
||||
|
||||
currentEntries = list;
|
||||
}
|
||||
|
||||
public ICell CreateCell(RectTransform cellTransform)
|
||||
{
|
||||
return CreateICell.Invoke(cellTransform);
|
||||
}
|
||||
|
||||
public void SetCell(ICell cell, int index)
|
||||
{
|
||||
if (index < 0 || index >= currentEntries.Count)
|
||||
cell.Disable();
|
||||
else
|
||||
{
|
||||
cell.Enable();
|
||||
SetICell.Invoke((SimpleCell<T>)cell, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Widgets.InfiniteScroll;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
|
@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Widgets.InfiniteScroll;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
|
@ -265,17 +265,21 @@
|
||||
<Compile Include="UI\Models\UIBehaviourModel.cs" />
|
||||
<Compile Include="UI\Models\UIModel.cs" />
|
||||
<Compile Include="UI\Models\UIPanel.cs" />
|
||||
<Compile Include="UI\Panels\GameObjectInspector.cs" />
|
||||
<Compile Include="UI\Panels\SceneExplorer.cs" />
|
||||
<Compile Include="UI\UIFactory.cs" />
|
||||
<Compile Include="UI\UIManager.cs" />
|
||||
<Compile Include="UI\Utility\PanelDragger.cs" />
|
||||
<Compile Include="UI\Utility\SignatureHighlighter.cs" />
|
||||
<Compile Include="UI\Utility\ToStringUtility.cs" />
|
||||
<Compile Include="UI\Widgets\InfiniteScroll\ICell.cs" />
|
||||
<Compile Include="UI\Widgets\InfiniteScroll\IListDataSource.cs" />
|
||||
<Compile Include="UI\Widgets\InfiniteScroll\InfiniteScrollRect.cs" />
|
||||
<Compile Include="UI\Widgets\InfiniteScroll\UIExtensions.cs" />
|
||||
<Compile Include="UI\Widgets\InputFieldScroller.cs" />
|
||||
<Compile Include="UI\Widgets\PageHandler.cs" />
|
||||
<Compile Include="UI\Widgets\SimpleList\SimpleCell.cs" />
|
||||
<Compile Include="UI\Widgets\SimpleList\SimpleListSource.cs" />
|
||||
<Compile Include="UI\Widgets\SliderScrollbar.cs" />
|
||||
<Compile Include="UI\Widgets\TransformTree\CachedTransform.cs" />
|
||||
<Compile Include="UI\Widgets\TransformTree\TransformCell.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user