Cleanup and fix small issue with JumpToIndex

This commit is contained in:
Sinai 2021-05-26 18:32:47 +10:00
parent 1a26623080
commit b0bbeb3cf8
4 changed files with 29 additions and 28 deletions

View File

@ -235,9 +235,6 @@ namespace UnityExplorer.UI.Inspectors
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);
}

View File

@ -63,6 +63,9 @@ namespace UnityExplorer.UI.ObjectExplorer
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)

View File

@ -137,14 +137,31 @@ namespace UnityExplorer.UI.Widgets
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));
}
// Slide to the normalized position
OnSliderValueChanged(normalized);
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;
// 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

View File

@ -32,8 +32,6 @@ namespace UnityExplorer.UI.Widgets
public int ItemCount => cachedTransforms.Count;
private readonly HashSet<int> highlightedTransforms = new HashSet<int>();
public bool Filtering => !string.IsNullOrEmpty(currentFilter);
private bool wasFiltering;
@ -119,30 +117,17 @@ namespace UnityExplorer.UI.Widgets
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);
@ -151,7 +136,6 @@ namespace UnityExplorer.UI.Widgets
yield return null;
button.OnDeselect(null);
highlightedTransforms.Remove(transformID);
}
public void Rebuild()