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

Commit

Permalink
Cleanup and fix small issue with JumpToIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
sinai-dev committed May 26, 2021
1 parent 1a26623 commit b0bbeb3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
3 changes: 0 additions & 3 deletions src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ private void OnTagEndEdit(string value)
private void OnExploreButtonClicked()
{
var panel = UIManager.GetPanel<Panels.ObjectExplorerPanel>(UIManager.Panels.ObjectExplorer);
UIManager.SetPanelActive(panel, true);
panel.SetTab(0);

panel.SceneExplorer.JumpToTransform(this.Parent.GOTarget.transform);
}

Expand Down
3 changes: 3 additions & 0 deletions src/UI/ObjectExplorer/SceneExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void JumpToTransform(Transform transform)
if (!transform)
return;

UIManager.SetPanelActive(this.Parent, true);
this.Parent.SetTab(0);

// select the transform's scene
var go = transform.gameObject;
if (SceneHandler.SelectedScene != go.scene)
Expand Down
23 changes: 20 additions & 3 deletions src/UI/Widgets/ScrollPool/ScrollPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,31 @@ public void Refresh(bool setCellData, bool jumpToTop = false)
RefreshCells(setCellData, true);
}

public void JumpToIndex(int index)
public void JumpToIndex(int index, Action<T> onJumped)
{
RefreshCells(true, true);

// Slide to the normalized position of the index
float normalized = HeightCache[index].startPosition / HeightCache.TotalHeight;
RuntimeProvider.Instance.StartCoroutine(ForceDelayedJump(index, normalized, onJumped));
}

private IEnumerator ForceDelayedJump(int dataIndex, float normalizedPos, Action<T> onJumped)
{
// Yielding two frames seems necessary in case the Explorer tab had not been opened before the jump.
yield return null;
yield return null;
slider.value = normalizedPos;

// Slide to the normalized position
OnSliderValueChanged(normalized);
// Get the cell containing the data index and invoke the onJumped listener for it
foreach (var cellInfo in this)
{
if (cellInfo.dataIndex == dataIndex)
{
onJumped?.Invoke(CellPool[cellInfo.cellIndex]);
break;
}
}
}

// IEnumerable
Expand Down
28 changes: 6 additions & 22 deletions src/UI/Widgets/TransformTree/TransformTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class TransformTree : ICellPoolDataSource<TransformCell>

public int ItemCount => cachedTransforms.Count;

private readonly HashSet<int> highlightedTransforms = new HashSet<int>();

public bool Filtering => !string.IsNullOrEmpty(currentFilter);
private bool wasFiltering;

Expand Down Expand Up @@ -119,30 +117,17 @@ public void JumpAndExpandToTransform(Transform transform)
if (cache.InstanceID == transformID)
break;
}
ScrollPool.JumpToIndex(idx);

// 'select' (highlight) the cell containing our transform
foreach (var cellInfo in ScrollPool)
{
var cell = ScrollPool.CellPool[cellInfo.cellIndex];

if (!cell.Enabled)
continue;

if (cell.cachedTransform.InstanceID == transformID)
{
RuntimeProvider.Instance.StartCoroutine(HighlightCellCoroutine(cell, transformID));
break;
}
}
ScrollPool.JumpToIndex(idx, OnCellJumpedTo);
}

private IEnumerator HighlightCellCoroutine(TransformCell cell, int transformID)
private void OnCellJumpedTo(TransformCell cell)
{
if (highlightedTransforms.Contains(transformID))
yield break;
highlightedTransforms.Add(transformID);
RuntimeProvider.Instance.StartCoroutine(HighlightCellCoroutine(cell));
}

private IEnumerator HighlightCellCoroutine(TransformCell cell)
{
var button = cell.NameButton.Component;
button.StartColorTween(new Color(0.2f, 0.3f, 0.2f), false);

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

button.OnDeselect(null);
highlightedTransforms.Remove(transformID);
}

public void Rebuild()
Expand Down

0 comments on commit b0bbeb3

Please sign in to comment.