Skip to content

Commit cf4f1e7

Browse files
committed
RuntimeHierarchy.Select now centers the Transform perfectly in the scroll view
1 parent 513d882 commit cf4f1e7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Plugins/RuntimeInspector/Scripts/RuntimeHierarchy.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,16 @@ public bool Select( Transform selection, bool forceSelection = false )
768768
itemIndex += sceneData[i].Height;
769769

770770
LayoutRebuilder.ForceRebuildLayoutImmediate( drawArea );
771-
scrollView.verticalNormalizedPosition = Mathf.Clamp01( 1f - (float) itemIndex / totalItemCount );
771+
772+
// Focus ScrollRect on selectionItem
773+
// Credit: https://gist.github.com/yasirkula/75ca350fb83ddcc1558d33a8ecf1483f
774+
float drawAreaHeight = drawArea.rect.height;
775+
float viewportHeight = ( (RectTransform) drawArea.parent ).rect.height;
776+
if( drawAreaHeight > viewportHeight )
777+
{
778+
float focusPoint = ( (float) itemIndex / totalItemCount ) * drawAreaHeight + Skin.LineHeight * 0.5f;
779+
scrollView.verticalNormalizedPosition = 1f - Mathf.Clamp01( ( focusPoint - viewportHeight * 0.5f ) / ( drawAreaHeight - viewportHeight ) );
780+
}
772781

773782
return true;
774783
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.runtimeinspector",
33
"displayName": "Runtime Inspector & Hierarchy",
4-
"version": "1.6.5",
4+
"version": "1.6.6",
55
"documentationUrl": "https://github.com/yasirkula/UnityRuntimeInspector",
66
"changelogUrl": "https://github.com/yasirkula/UnityRuntimeInspector/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnityRuntimeInspector/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)