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

Commit b0bbeb3

Browse files
committed
Cleanup and fix small issue with JumpToIndex
1 parent 1a26623 commit b0bbeb3

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ private void OnTagEndEdit(string value)
235235
private void OnExploreButtonClicked()
236236
{
237237
var panel = UIManager.GetPanel<Panels.ObjectExplorerPanel>(UIManager.Panels.ObjectExplorer);
238-
UIManager.SetPanelActive(panel, true);
239-
panel.SetTab(0);
240-
241238
panel.SceneExplorer.JumpToTransform(this.Parent.GOTarget.transform);
242239
}
243240

src/UI/ObjectExplorer/SceneExplorer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public void JumpToTransform(Transform transform)
6363
if (!transform)
6464
return;
6565

66+
UIManager.SetPanelActive(this.Parent, true);
67+
this.Parent.SetTab(0);
68+
6669
// select the transform's scene
6770
var go = transform.gameObject;
6871
if (SceneHandler.SelectedScene != go.scene)

src/UI/Widgets/ScrollPool/ScrollPool.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,31 @@ public void Refresh(bool setCellData, bool jumpToTop = false)
137137
RefreshCells(setCellData, true);
138138
}
139139

140-
public void JumpToIndex(int index)
140+
public void JumpToIndex(int index, Action<T> onJumped)
141141
{
142142
RefreshCells(true, true);
143143

144+
// Slide to the normalized position of the index
144145
float normalized = HeightCache[index].startPosition / HeightCache.TotalHeight;
146+
RuntimeProvider.Instance.StartCoroutine(ForceDelayedJump(index, normalized, onJumped));
147+
}
148+
149+
private IEnumerator ForceDelayedJump(int dataIndex, float normalizedPos, Action<T> onJumped)
150+
{
151+
// Yielding two frames seems necessary in case the Explorer tab had not been opened before the jump.
152+
yield return null;
153+
yield return null;
154+
slider.value = normalizedPos;
145155

146-
// Slide to the normalized position
147-
OnSliderValueChanged(normalized);
156+
// Get the cell containing the data index and invoke the onJumped listener for it
157+
foreach (var cellInfo in this)
158+
{
159+
if (cellInfo.dataIndex == dataIndex)
160+
{
161+
onJumped?.Invoke(CellPool[cellInfo.cellIndex]);
162+
break;
163+
}
164+
}
148165
}
149166

150167
// IEnumerable

src/UI/Widgets/TransformTree/TransformTree.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public class TransformTree : ICellPoolDataSource<TransformCell>
3232

3333
public int ItemCount => cachedTransforms.Count;
3434

35-
private readonly HashSet<int> highlightedTransforms = new HashSet<int>();
36-
3735
public bool Filtering => !string.IsNullOrEmpty(currentFilter);
3836
private bool wasFiltering;
3937

@@ -119,30 +117,17 @@ public void JumpAndExpandToTransform(Transform transform)
119117
if (cache.InstanceID == transformID)
120118
break;
121119
}
122-
ScrollPool.JumpToIndex(idx);
123-
124-
// 'select' (highlight) the cell containing our transform
125-
foreach (var cellInfo in ScrollPool)
126-
{
127-
var cell = ScrollPool.CellPool[cellInfo.cellIndex];
128120

129-
if (!cell.Enabled)
130-
continue;
131-
132-
if (cell.cachedTransform.InstanceID == transformID)
133-
{
134-
RuntimeProvider.Instance.StartCoroutine(HighlightCellCoroutine(cell, transformID));
135-
break;
136-
}
137-
}
121+
ScrollPool.JumpToIndex(idx, OnCellJumpedTo);
138122
}
139123

140-
private IEnumerator HighlightCellCoroutine(TransformCell cell, int transformID)
124+
private void OnCellJumpedTo(TransformCell cell)
141125
{
142-
if (highlightedTransforms.Contains(transformID))
143-
yield break;
144-
highlightedTransforms.Add(transformID);
126+
RuntimeProvider.Instance.StartCoroutine(HighlightCellCoroutine(cell));
127+
}
145128

129+
private IEnumerator HighlightCellCoroutine(TransformCell cell)
130+
{
146131
var button = cell.NameButton.Component;
147132
button.StartColorTween(new Color(0.2f, 0.3f, 0.2f), false);
148133

@@ -151,7 +136,6 @@ private IEnumerator HighlightCellCoroutine(TransformCell cell, int transformID)
151136
yield return null;
152137

153138
button.OnDeselect(null);
154-
highlightedTransforms.Remove(transformID);
155139
}
156140

157141
public void Rebuild()

0 commit comments

Comments
 (0)