From b0bbeb3cf8709e8e673e65616adc12a0971dff73 Mon Sep 17 00:00:00 2001 From: Sinai Date: Wed, 26 May 2021 18:32:47 +1000 Subject: [PATCH] Cleanup and fix small issue with JumpToIndex --- .../GameObjectWidgets/GameObjectControls.cs | 3 -- src/UI/ObjectExplorer/SceneExplorer.cs | 3 ++ src/UI/Widgets/ScrollPool/ScrollPool.cs | 23 +++++++++++++-- src/UI/Widgets/TransformTree/TransformTree.cs | 28 ++++--------------- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs b/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs index dc150394..6d1b29f0 100644 --- a/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs +++ b/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs @@ -235,9 +235,6 @@ private void OnTagEndEdit(string value) private void OnExploreButtonClicked() { var panel = UIManager.GetPanel(UIManager.Panels.ObjectExplorer); - UIManager.SetPanelActive(panel, true); - panel.SetTab(0); - panel.SceneExplorer.JumpToTransform(this.Parent.GOTarget.transform); } diff --git a/src/UI/ObjectExplorer/SceneExplorer.cs b/src/UI/ObjectExplorer/SceneExplorer.cs index 1d02af10..36cc15c3 100644 --- a/src/UI/ObjectExplorer/SceneExplorer.cs +++ b/src/UI/ObjectExplorer/SceneExplorer.cs @@ -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) diff --git a/src/UI/Widgets/ScrollPool/ScrollPool.cs b/src/UI/Widgets/ScrollPool/ScrollPool.cs index b3f073c8..c46612f0 100644 --- a/src/UI/Widgets/ScrollPool/ScrollPool.cs +++ b/src/UI/Widgets/ScrollPool/ScrollPool.cs @@ -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 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 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 diff --git a/src/UI/Widgets/TransformTree/TransformTree.cs b/src/UI/Widgets/TransformTree/TransformTree.cs index 7e0c16eb..e5a938f6 100644 --- a/src/UI/Widgets/TransformTree/TransformTree.cs +++ b/src/UI/Widgets/TransformTree/TransformTree.cs @@ -32,8 +32,6 @@ public class TransformTree : ICellPoolDataSource public int ItemCount => cachedTransforms.Count; - private readonly HashSet highlightedTransforms = new HashSet(); - public bool Filtering => !string.IsNullOrEmpty(currentFilter); private bool wasFiltering; @@ -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); @@ -151,7 +136,6 @@ private IEnumerator HighlightCellCoroutine(TransformCell cell, int transformID) yield return null; button.OnDeselect(null); - highlightedTransforms.Remove(transformID); } public void Rebuild()