Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 041f293

Browse files
committed
Implement jumping to index in TransformTree
1 parent 9e7bb1a commit 041f293

File tree

4 files changed

+160
-75
lines changed

4 files changed

+160
-75
lines changed

src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ private void OnTagEndEdit(string value)
232232
}
233233
}
234234

235+
private void OnExploreButtonClicked()
236+
{
237+
var panel = UIManager.GetPanel<Panels.ObjectExplorerPanel>(UIManager.Panels.ObjectExplorer);
238+
UIManager.SetPanelActive(panel, true);
239+
panel.SetTab(0);
240+
241+
panel.SceneExplorer.JumpToTransform(this.Parent.GOTarget.transform);
242+
}
243+
235244
private void OnLayerDropdownChanged(int value)
236245
{
237246
GOTarget.layer = value;
@@ -533,6 +542,12 @@ private void ConstructTopInfo()
533542
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(thirdrow, false, false, true, true, 5, 0, 0, 0, 0, default);
534543
UIFactory.SetLayoutElement(thirdrow, minHeight: 25, flexibleWidth: 9999);
535544

545+
// Inspect in Explorer button
546+
var explorerBtn = UIFactory.CreateButton(thirdrow, "ExploreBtn", "Show in Explorer", new Color(0.15f, 0.15f, 0.15f));
547+
UIFactory.SetLayoutElement(explorerBtn.Component.gameObject, minHeight: 25, minWidth: 100);
548+
explorerBtn.ButtonText.fontSize = 12;
549+
explorerBtn.OnClick += OnExploreButtonClicked;
550+
536551
// Scene
537552
var sceneLabel = UIFactory.CreateLabel(thirdrow, "SceneLabel", "Scene:", TextAnchor.MiddleLeft, Color.grey);
538553
UIFactory.SetLayoutElement(sceneLabel.gameObject, minHeight: 25, minWidth: 50);
@@ -547,7 +562,7 @@ private void ConstructTopInfo()
547562
UIFactory.SetLayoutElement(layerLabel.gameObject, minHeight: 25, minWidth: 50);
548563

549564
var layerDrop = UIFactory.CreateDropdown(thirdrow, out LayerDropdown, "0", 14, OnLayerDropdownChanged);
550-
UIFactory.SetLayoutElement(layerDrop, minHeight: 25, minWidth: 120, flexibleWidth: 999);
565+
UIFactory.SetLayoutElement(layerDrop, minHeight: 25, minWidth: 110, flexibleWidth: 999);
551566
LayerDropdown.captionText.color = SignatureHighlighter.EnumGreen;
552567
if (layerToNames == null)
553568
GetLayerNames();

src/UI/ObjectExplorer/SceneExplorer.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ public void UpdateTree()
5858
Tree.RefreshData(true);
5959
}
6060

61+
public void JumpToTransform(Transform transform)
62+
{
63+
if (!transform)
64+
return;
65+
66+
// select the transform's scene
67+
var go = transform.gameObject;
68+
if (SceneHandler.SelectedScene != go.scene)
69+
{
70+
int idx = sceneDropdown.options.IndexOf(sceneToDropdownOption[go.scene.handle]);
71+
sceneDropdown.value = idx;
72+
}
73+
74+
// Let the TransformTree handle the rest
75+
Tree.JumpAndExpandToTransform(transform);
76+
}
77+
6178
private void OnDropdownChanged(int value)
6279
{
6380
if (value < 0 || SceneHandler.LoadedScenes.Count <= value)
@@ -122,7 +139,7 @@ private void OnFilterInput(string input)
122139
{
123140
if ((!string.IsNullOrEmpty(input) && !Tree.Filtering) || (string.IsNullOrEmpty(input) && Tree.Filtering))
124141
{
125-
Tree.displayedObjects.Clear();
142+
Tree.cachedTransforms.Clear();
126143
}
127144

128145
Tree.CurrentFilter = input;

src/UI/Widgets/ScrollPool/ScrollPool.cs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using UnityEngine.UI;
88
using UnityExplorer.Core.Input;
99
using UnityExplorer.UI.Models;
10-
using UnityExplorer.UI.ObjectPool;
1110
using UnityExplorer.UI.Panels;
1211

1312
namespace UnityExplorer.UI.Widgets
@@ -20,7 +19,7 @@ public struct CellInfo
2019
/// <summary>
2120
/// An object-pooled ScrollRect, attempts to support content of any size and provide a scrollbar for it.
2221
/// </summary>
23-
public class ScrollPool<T> : UIBehaviourModel where T : ICell
22+
public class ScrollPool<T> : UIBehaviourModel, IEnumerable<CellInfo> where T : ICell
2423
{
2524
public ScrollPool(ScrollRect scrollRect)
2625
{
@@ -138,9 +137,23 @@ public void Refresh(bool setCellData, bool jumpToTop = false)
138137
RefreshCells(setCellData, true);
139138
}
140139

141-
// Initialize
140+
public void JumpToIndex(int index)
141+
{
142+
RefreshCells(true, true);
143+
144+
float normalized = HeightCache[index].startPosition / HeightCache.TotalHeight;
145+
146+
// Slide to the normalized position
147+
OnSliderValueChanged(normalized);
148+
}
149+
150+
// IEnumerable
142151

143-
//private bool Initialized;
152+
public IEnumerator<CellInfo> GetEnumerator() => EnumerateCellPool();
153+
154+
IEnumerator IEnumerable.GetEnumerator() => EnumerateCellPool();
155+
156+
// Initialize
144157

145158
/// <summary>Should be called only once, when the scroll pool is created.</summary>
146159
public void Initialize(ICellPoolDataSource<T> dataSource, Action onHeightChangedListener = null)
@@ -178,9 +191,8 @@ private IEnumerator InitCoroutine(Action onHeightChangedListener)
178191
// create initial cell pool and set cells
179192
CreateCellPool();
180193

181-
var enumerator = GetPoolEnumerator();
182-
while (enumerator.MoveNext())
183-
SetCell(CellPool[enumerator.Current.cellIndex], enumerator.Current.dataIndex);
194+
foreach (var cell in this)
195+
SetCell(CellPool[cell.cellIndex], cell.dataIndex);
184196

185197
LayoutRebuilder.ForceRebuildLayoutImmediate(Content);
186198
prevContentHeight = Content.rect.height;
@@ -217,18 +229,18 @@ private bool CheckRecycleViewBounds(bool extendPoolIfGrown)
217229

218230
// Cell pool
219231

220-
private CellInfo _cellInfo = new CellInfo();
232+
private CellInfo _current;
221233

222-
public IEnumerator<CellInfo> GetPoolEnumerator()
234+
private IEnumerator<CellInfo> EnumerateCellPool()
223235
{
224236
int cellIdx = topPoolIndex;
225237
int dataIndex = TopDataIndex;
226238
int iterated = 0;
227239
while (iterated < CellPool.Count)
228240
{
229-
_cellInfo.cellIndex = cellIdx;
230-
_cellInfo.dataIndex = dataIndex;
231-
yield return _cellInfo;
241+
_current.cellIndex = cellIdx;
242+
_current.dataIndex = dataIndex;
243+
yield return _current;
232244

233245
cellIdx++;
234246
if (cellIdx >= CellPool.Count)
@@ -368,16 +380,13 @@ private void RefreshCells(bool andReloadFromDataSource, bool setSlider)
368380
CheckDataSourceCountChange(out bool jumpToBottom);
369381

370382
// update date height cache, and set cells if 'andReload'
371-
var enumerator = GetPoolEnumerator();
372-
while (enumerator.MoveNext())
383+
foreach (var cellInfo in this)
373384
{
374-
var curr = enumerator.Current;
375-
var cell = CellPool[curr.cellIndex];
376-
385+
var cell = CellPool[cellInfo.cellIndex];
377386
if (andReloadFromDataSource)
378-
SetCell(cell, curr.dataIndex);
387+
SetCell(cell, cellInfo.dataIndex);
379388
else
380-
HeightCache.SetIndex(curr.dataIndex, cell.Rect.rect.height);
389+
HeightCache.SetIndex(cellInfo.dataIndex, cell.Rect.rect.height);
381390
}
382391

383392
// force check recycles
@@ -405,12 +414,8 @@ private void RefreshCells(bool andReloadFromDataSource, bool setSlider)
405414

406415
private void RefreshCellHeightsFast()
407416
{
408-
var enumerator = GetPoolEnumerator();
409-
while (enumerator.MoveNext())
410-
{
411-
var curr = enumerator.Current;
412-
HeightCache.SetIndex(curr.dataIndex, CellPool[curr.cellIndex].Rect.rect.height);
413-
}
417+
foreach (var cellInfo in this)
418+
HeightCache.SetIndex(cellInfo.dataIndex, CellPool[cellInfo.cellIndex].Rect.rect.height);
414419
}
415420

416421
private void SetCell(T cachedCell, int dataIndex)
@@ -619,12 +624,10 @@ private void OnSliderValueChanged(float val)
619624
else
620625
{
621626
bottomDataIndex = desiredBottomIndex;
622-
var enumerator = GetPoolEnumerator();
623-
while (enumerator.MoveNext())
627+
foreach (var info in this)
624628
{
625-
var curr = enumerator.Current;
626-
var cell = CellPool[curr.cellIndex];
627-
SetCell(cell, curr.dataIndex);
629+
var cell = CellPool[info.cellIndex];
630+
SetCell(cell, info.dataIndex);
628631
}
629632
}
630633

0 commit comments

Comments
 (0)