mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-03 03:52:28 +08:00
Finish GameObject Inspector, some UI cleanups
This commit is contained in:
@ -16,6 +16,7 @@ namespace UnityExplorer.UI.Widgets
|
||||
public int Depth { get; internal set; }
|
||||
public int ChildCount { get; internal set; }
|
||||
public string Name { get; internal set; }
|
||||
public bool Enabled { get; internal set; }
|
||||
|
||||
public bool Expanded => Tree.IsCellExpanded(InstanceID);
|
||||
|
||||
@ -32,12 +33,17 @@ namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
if (Value != transform || depth != Depth || ChildCount != transform.childCount || Name != transform.name)
|
||||
if (Value != transform
|
||||
|| depth != Depth
|
||||
|| ChildCount != transform.childCount
|
||||
|| Name != transform.name
|
||||
|| Enabled != transform.gameObject.activeSelf)
|
||||
{
|
||||
Value = transform;
|
||||
Depth = depth;
|
||||
ChildCount = transform.childCount;
|
||||
Name = transform.name;
|
||||
Enabled = transform.gameObject.activeSelf;
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
|
@ -17,6 +17,7 @@ namespace UnityExplorer.UI.Widgets
|
||||
private bool m_enabled;
|
||||
|
||||
public Action<CachedTransform> OnExpandToggled;
|
||||
public Action<GameObject> OnGameObjectClicked;
|
||||
|
||||
public CachedTransform cachedTransform;
|
||||
public int _cellIndex;
|
||||
@ -29,6 +30,14 @@ namespace UnityExplorer.UI.Widgets
|
||||
|
||||
public LayoutElement spacer;
|
||||
|
||||
public void OnMainButtonClicked()
|
||||
{
|
||||
if (cachedTransform.Value)
|
||||
OnGameObjectClicked?.Invoke(cachedTransform.Value.gameObject);
|
||||
else
|
||||
ExplorerCore.LogWarning("The object was destroyed!");
|
||||
}
|
||||
|
||||
public void ConfigureCell(CachedTransform cached, int cellIndex)
|
||||
{
|
||||
if (cached == null)
|
||||
@ -90,14 +99,6 @@ namespace UnityExplorer.UI.Widgets
|
||||
OnExpandToggled?.Invoke(cachedTransform);
|
||||
}
|
||||
|
||||
public void OnMainButtonClicked()
|
||||
{
|
||||
if (cachedTransform.Value)
|
||||
InspectorManager.Inspect(cachedTransform.Value.gameObject);
|
||||
else
|
||||
ExplorerCore.LogWarning("The object was destroyed!");
|
||||
}
|
||||
|
||||
public GameObject CreateContent(GameObject parent)
|
||||
{
|
||||
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
||||
|
@ -14,15 +14,15 @@ namespace UnityExplorer.UI.Widgets
|
||||
public class TransformTree : ICellPoolDataSource<TransformCell>
|
||||
{
|
||||
public Func<IEnumerable<GameObject>> GetRootEntriesMethod;
|
||||
public Action<GameObject> OnClickOverrideHandler;
|
||||
|
||||
internal ScrollPool<TransformCell> ScrollPool;
|
||||
public ScrollPool<TransformCell> ScrollPool;
|
||||
|
||||
// Using an OrderedDictionary because we need constant-time lookup of both key and index.
|
||||
/// <summary>
|
||||
/// Key: UnityEngine.Transform instance ID<br/>
|
||||
/// Value: CachedTransform
|
||||
/// </summary>
|
||||
private readonly OrderedDictionary displayedObjects = new OrderedDictionary();
|
||||
internal readonly OrderedDictionary displayedObjects = new OrderedDictionary();
|
||||
|
||||
// for keeping track of which actual transforms are expanded or not, outside of the cache data.
|
||||
private readonly HashSet<int> expandedInstanceIDs = new HashSet<int>();
|
||||
@ -50,9 +50,22 @@ namespace UnityExplorer.UI.Widgets
|
||||
}
|
||||
private string currentFilter;
|
||||
|
||||
public TransformTree(ScrollPool<TransformCell> scrollPool)
|
||||
public void OnGameObjectClicked(GameObject obj)
|
||||
{
|
||||
if (OnClickOverrideHandler != null)
|
||||
{
|
||||
OnClickOverrideHandler.Invoke(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
InspectorManager.Inspect(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public TransformTree(ScrollPool<TransformCell> scrollPool, Func<IEnumerable<GameObject>> getRootEntriesMethod)
|
||||
{
|
||||
ScrollPool = scrollPool;
|
||||
GetRootEntriesMethod = getRootEntriesMethod;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
@ -60,8 +73,6 @@ namespace UnityExplorer.UI.Widgets
|
||||
ScrollPool.Initialize(this);
|
||||
}
|
||||
|
||||
//public void DisableCell(TransformCell cell, int index) => cell.Disable();
|
||||
|
||||
|
||||
public bool IsCellExpanded(int instanceID)
|
||||
{
|
||||
@ -124,16 +135,19 @@ namespace UnityExplorer.UI.Widgets
|
||||
|
||||
if (visited.Contains(instanceID))
|
||||
return;
|
||||
visited.Add(instanceID);
|
||||
|
||||
if (Filtering)
|
||||
{
|
||||
if (!FilterHierarchy(transform))
|
||||
return;
|
||||
|
||||
visited.Add(instanceID);
|
||||
|
||||
if (!autoExpandedIDs.Contains(instanceID))
|
||||
autoExpandedIDs.Add(instanceID);
|
||||
}
|
||||
else
|
||||
visited.Add(instanceID);
|
||||
|
||||
CachedTransform cached;
|
||||
if (displayedObjects.Contains(instanceID))
|
||||
@ -179,7 +193,16 @@ namespace UnityExplorer.UI.Widgets
|
||||
public void SetCell(TransformCell cell, int index)
|
||||
{
|
||||
if (index < displayedObjects.Count)
|
||||
{
|
||||
cell.ConfigureCell((CachedTransform)displayedObjects[index], index);
|
||||
if (Filtering)
|
||||
{
|
||||
if (cell.cachedTransform.Name.ContainsIgnoreCase(currentFilter))
|
||||
{
|
||||
cell.NameButton.ButtonText.color = Color.green;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
cell.Disable();
|
||||
}
|
||||
@ -198,11 +221,12 @@ namespace UnityExplorer.UI.Widgets
|
||||
public void OnCellBorrowed(TransformCell cell)
|
||||
{
|
||||
cell.OnExpandToggled += ToggleExpandCell;
|
||||
cell.OnGameObjectClicked += OnGameObjectClicked;
|
||||
}
|
||||
|
||||
public void ReleaseCell(TransformCell cell)
|
||||
{
|
||||
cell.OnExpandToggled -= ToggleExpandCell;
|
||||
}
|
||||
//public void ReleaseCell(TransformCell cell)
|
||||
//{
|
||||
// cell.OnExpandToggled -= ToggleExpandCell;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user