mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-15 15:57:52 +08:00
Some UI cleanups, improving caching and reduce image allocation
This commit is contained in:
@ -106,7 +106,7 @@ namespace UnityExplorer.UI.Inspectors
|
||||
var closeBtn = UIFactory.CreateButton(tabGroupObj,
|
||||
"CloseButton",
|
||||
"X",
|
||||
parent.Destroy,
|
||||
() => { InspectorManager.DestroyInspector(parent); },
|
||||
new Color(0.2f, 0.2f, 0.2f, 1));
|
||||
|
||||
UIFactory.SetLayoutElement(closeBtn.gameObject, minWidth: 20, flexibleWidth: 0);
|
||||
|
@ -30,6 +30,14 @@ namespace UnityExplorer.UI.Inspectors
|
||||
}
|
||||
}
|
||||
|
||||
public static void DestroyInspector(InspectorBase inspector)
|
||||
{
|
||||
if (inspector is ReflectionInspector ri)
|
||||
ri.Destroy();
|
||||
else
|
||||
inspector.Destroy();
|
||||
}
|
||||
|
||||
public static void Inspect(object obj, CacheObjectBase parentMember = null)
|
||||
{
|
||||
var type = ReflectionProvider.Instance.GetActualType(obj);
|
||||
@ -70,7 +78,7 @@ namespace UnityExplorer.UI.Inspectors
|
||||
SetInspectorTab(inspector);
|
||||
}
|
||||
|
||||
public static void InspectType(Type type)
|
||||
public static void Inspect(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
|
@ -29,48 +29,33 @@ namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
|
||||
public ICell CreateCell(RectTransform cellTransform) => new CellViewHolder(cellTransform.gameObject);
|
||||
|
||||
public void DisableCell(ICell cell, int index)
|
||||
{
|
||||
var root = (cell as CellViewHolder).UIRoot;
|
||||
DisableContent(root);
|
||||
cell.Disable();
|
||||
}
|
||||
|
||||
public void SetCell(ICell icell, int index)
|
||||
{
|
||||
var root = (icell as CellViewHolder).UIRoot;
|
||||
var cell = icell as CellViewHolder;
|
||||
|
||||
if (index < 0 || index >= ItemCount)
|
||||
{
|
||||
DisableContent(root);
|
||||
icell.Disable();
|
||||
var existing = cell.DisableContent();
|
||||
if (existing)
|
||||
existing.transform.SetParent(Inspector.InactiveHolder.transform, false);
|
||||
return;
|
||||
}
|
||||
|
||||
float start = Time.realtimeSinceStartup;
|
||||
index = GetRealIndexOfTempIndex(index);
|
||||
|
||||
var cache = Inspector.allMembers[index];
|
||||
cache.Enable();
|
||||
|
||||
var content = cache.UIRoot;
|
||||
|
||||
if (content.transform.parent.ReferenceEqual(root.transform))
|
||||
return;
|
||||
|
||||
var orig = content.transform.parent;
|
||||
|
||||
DisableContent(root);
|
||||
|
||||
content.transform.SetParent(root.transform, false);
|
||||
//ExplorerCore.Log("Set cell " + index + ", took " + (Time.realtimeSinceStartup - start) + " secs");
|
||||
//ExplorerCore.Log("orig parent was " + (orig?.name ?? " <null>"));
|
||||
var prev = cell.SetContent(cache.UIRoot);
|
||||
if (prev)
|
||||
prev.transform.SetParent(Inspector.InactiveHolder.transform, false);
|
||||
}
|
||||
|
||||
private void DisableContent(GameObject cellRoot)
|
||||
public void DisableCell(ICell cell, int index)
|
||||
{
|
||||
if (cellRoot.transform.childCount > 0 && cellRoot.transform.GetChild(0) is Transform existing)
|
||||
existing.transform.SetParent(Inspector.InactiveHolder.transform, false);
|
||||
var content = (cell as CellViewHolder).DisableContent();
|
||||
if (content)
|
||||
content.transform.SetParent(Inspector.InactiveHolder.transform, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
|
||||
FilterMembers(null, true);
|
||||
|
||||
ScrollPool.EnableTempCache();
|
||||
ScrollPool.RecreateHeightCache();
|
||||
ScrollPool.RefreshAndJumpToTop();
|
||||
//RefreshDisplay();
|
||||
//m_sliderScroller.m_slider.value = 1f;
|
||||
@ -134,23 +134,21 @@ namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
|
||||
internal void ConstructTextureHelper()
|
||||
{
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(Content, "TextureHelper", true, false, true, true, 5, new Vector4(3, 3, 3, 3),
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(Content, "TextureHelper", false, false, true, true, 5, new Vector4(3, 3, 3, 3),
|
||||
new Color(0.1f, 0.1f, 0.1f));
|
||||
UIFactory.SetLayoutElement(rowObj, minHeight: 25, flexibleHeight: 0);
|
||||
|
||||
var showBtn = UIFactory.CreateButton(rowObj, "ShowButton", "Show", null, new Color(0.2f, 0.6f, 0.2f));
|
||||
UIFactory.SetLayoutElement(showBtn.gameObject, minWidth: 50, flexibleWidth: 0);
|
||||
var showBtn = UIFactory.CreateButton(rowObj, "ShowButton", "Show", null, new Color(0.2f, 0.3f, 0.2f));
|
||||
UIFactory.SetLayoutElement(showBtn.gameObject, minWidth: 50, flexibleWidth: 0, minHeight: 20);
|
||||
|
||||
UIFactory.CreateLabel(rowObj, "TextureViewerLabel", "Texture Viewer", TextAnchor.MiddleLeft);
|
||||
|
||||
var textureViewerObj = UIFactory.CreateScrollView(Content, "TextureViewerContent", out GameObject scrollContent, out _,
|
||||
m_textureViewerObj = UIFactory.CreateScrollView(Content, "TextureViewerContent", out GameObject scrollContent, out _,
|
||||
new Color(0.1f, 0.1f, 0.1f));
|
||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(textureViewerObj, false, false, true, true);
|
||||
UIFactory.SetLayoutElement(textureViewerObj, minHeight: 100, flexibleHeight: 9999, flexibleWidth: 9999);
|
||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(scrollContent, false, false, true, true);
|
||||
UIFactory.SetLayoutElement(m_textureViewerObj, minHeight: 100, flexibleHeight: 9999, flexibleWidth: 9999);
|
||||
|
||||
textureViewerObj.SetActive(false);
|
||||
|
||||
m_textureViewerObj = textureViewerObj;
|
||||
m_textureViewerObj.SetActive(false);
|
||||
|
||||
var showText = showBtn.GetComponentInChildren<Text>();
|
||||
showBtn.onClick.AddListener(() =>
|
||||
@ -249,7 +247,7 @@ namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
m_textureViewerObj.SetActive(enabled);
|
||||
|
||||
m_filterAreaObj.SetActive(!enabled);
|
||||
//m_memberListObj.SetActive(!enabled);
|
||||
this.ScrollPool.UIRoot.SetActive(!enabled);
|
||||
m_updateRowObj.SetActive(!enabled);
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,10 @@ namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
base.Destroy();
|
||||
|
||||
if (this.Content)
|
||||
{
|
||||
GameObject.Destroy(this.InactiveHolder);
|
||||
GameObject.Destroy(this.Content);
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsBlacklisted(string sig) => bl_typeAndMember.Any(it => sig.Contains(it));
|
||||
@ -262,7 +265,7 @@ namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton, new Color(0.2f, 0.6f, 0.2f));
|
||||
|
||||
FilterMembers(null, true);
|
||||
ScrollPool.EnableTempCache();
|
||||
ScrollPool.RecreateHeightCache();
|
||||
ScrollPool.Rebuild();
|
||||
}
|
||||
|
||||
@ -332,7 +335,7 @@ namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
new Color(0.15f, 0.15f, 0.15f));
|
||||
|
||||
this.m_inactiveHolder = new GameObject("InactiveContentHolder");
|
||||
m_inactiveHolder.transform.SetParent(parent.transform, false);
|
||||
m_inactiveHolder.transform.SetParent(Content.transform, false);
|
||||
m_inactiveHolder.SetActive(false);
|
||||
|
||||
ConstructTopArea();
|
||||
@ -389,7 +392,7 @@ namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
nameInput.onValueChanged.AddListener((string val) =>
|
||||
{
|
||||
FilterMembers(val, true);
|
||||
ScrollPool.EnableTempCache();
|
||||
ScrollPool.RecreateHeightCache();
|
||||
ScrollPool.Rebuild();
|
||||
});
|
||||
m_nameFilterText = nameInput.textComponent;
|
||||
|
Reference in New Issue
Block a user