All working but codex.
This commit is contained in:
@@ -17,51 +17,28 @@ namespace BriarQueen.UI.Menus
|
||||
private static readonly Vector3[] Corners = new Vector3[4];
|
||||
|
||||
[Header("Hierarchy")]
|
||||
[SerializeField]
|
||||
private RectTransform _viewport;
|
||||
|
||||
[SerializeField]
|
||||
private RectTransform _content;
|
||||
|
||||
[SerializeField]
|
||||
private RectTransform _trackRect;
|
||||
|
||||
[SerializeField]
|
||||
private RectTransform _handleRect;
|
||||
|
||||
[SerializeField]
|
||||
private Image _scrollBarImage;
|
||||
[SerializeField] private RectTransform _viewport;
|
||||
[SerializeField] private RectTransform _content;
|
||||
[SerializeField] private RectTransform _trackRect;
|
||||
[SerializeField] private RectTransform _handleRect;
|
||||
[SerializeField] private Image _scrollBarImage;
|
||||
|
||||
[Header("Scroll Settings")]
|
||||
[SerializeField]
|
||||
private float _wheelPixels = 80f;
|
||||
|
||||
[SerializeField]
|
||||
private float _padSpeed = 900f;
|
||||
|
||||
[SerializeField]
|
||||
private float _inputSystemWheelScale = 0.05f;
|
||||
[SerializeField] private float _wheelPixels = 80f;
|
||||
[SerializeField] private float _padSpeed = 900f;
|
||||
[SerializeField] private float _inputSystemWheelScale = 0.05f;
|
||||
|
||||
[Header("Handle")]
|
||||
[SerializeField]
|
||||
private bool _useCustomHandleSizing;
|
||||
|
||||
[SerializeField]
|
||||
private float _minHandleHeight = 24f;
|
||||
[SerializeField] private bool _useCustomHandleSizing;
|
||||
[SerializeField] private float _minHandleHeight = 24f;
|
||||
|
||||
[Header("Alignment")]
|
||||
[SerializeField]
|
||||
private bool _centerContentWhenNotScrollable = true;
|
||||
|
||||
[SerializeField]
|
||||
private float _topInset = 6f;
|
||||
|
||||
[SerializeField]
|
||||
private float _bottomInset = 6f;
|
||||
[SerializeField] private bool _centerContentWhenNotScrollable = true;
|
||||
[SerializeField] private float _topInset = 6f;
|
||||
[SerializeField] private float _bottomInset = 6f;
|
||||
|
||||
[Header("Track")]
|
||||
[SerializeField]
|
||||
private bool _hideTrackWhenNotScrollable = true;
|
||||
[SerializeField] private bool _hideTrackWhenNotScrollable = true;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[Header("Editor Debug")]
|
||||
@@ -70,7 +47,7 @@ namespace BriarQueen.UI.Menus
|
||||
private float _debugNormalized;
|
||||
#endif
|
||||
|
||||
private bool _isScrollable;
|
||||
private bool _isScrollable;
|
||||
private float _scrollRange;
|
||||
private Camera _uiCamera;
|
||||
|
||||
@@ -108,11 +85,14 @@ namespace BriarQueen.UI.Menus
|
||||
if (!TryGetContentBounds(out var top, out var bottom))
|
||||
return;
|
||||
|
||||
var contentHeight = top - bottom;
|
||||
var contentHeight = top - bottom;
|
||||
var viewportHeight = _viewport.rect.height - _topInset - _bottomInset;
|
||||
|
||||
_isScrollable = contentHeight > viewportHeight;
|
||||
_scrollRange = Mathf.Max(0f, contentHeight - viewportHeight);
|
||||
_scrollRange = Mathf.Max(0f, contentHeight - viewportHeight);
|
||||
|
||||
Debug.Log($"[Scrollbar] OnValidate — contentHeight:{contentHeight} viewportHeight:{viewportHeight} isScrollable:{_isScrollable} scrollRange:{_scrollRange}");
|
||||
|
||||
Normalized = Mathf.Clamp01(_debugNormalized);
|
||||
|
||||
if (_centerContentWhenNotScrollable && !_isScrollable)
|
||||
@@ -155,11 +135,13 @@ namespace BriarQueen.UI.Menus
|
||||
if (!TryGetContentBounds(out var top, out var bottom))
|
||||
return;
|
||||
|
||||
var contentHeight = top - bottom;
|
||||
var contentHeight = top - bottom;
|
||||
var viewportHeight = _viewport.rect.height - _topInset - _bottomInset;
|
||||
|
||||
_isScrollable = contentHeight > viewportHeight;
|
||||
_scrollRange = Mathf.Max(0f, contentHeight - viewportHeight);
|
||||
_scrollRange = Mathf.Max(0f, contentHeight - viewportHeight);
|
||||
|
||||
Debug.Log($"[Scrollbar] Rebuild — contentHeight:{contentHeight} viewportHeight:{viewportHeight} isScrollable:{_isScrollable} scrollRange:{_scrollRange}");
|
||||
|
||||
if (_centerContentWhenNotScrollable && !_isScrollable)
|
||||
{
|
||||
@@ -179,6 +161,8 @@ namespace BriarQueen.UI.Menus
|
||||
{
|
||||
Normalized = Mathf.Clamp01(normalized);
|
||||
|
||||
Debug.Log($"[Scrollbar] SetNormalized:{normalized} isScrollable:{_isScrollable} scrollRange:{_scrollRange}");
|
||||
|
||||
if (!_isScrollable)
|
||||
return;
|
||||
|
||||
@@ -193,13 +177,13 @@ namespace BriarQueen.UI.Menus
|
||||
|
||||
private void CenterContent(float top, float bottom)
|
||||
{
|
||||
var contentCenter = (top + bottom) * 0.5f;
|
||||
var contentCenter = (top + bottom) * 0.5f;
|
||||
var viewportCenter = (_viewport.rect.yMin + _viewport.rect.yMax) * 0.5f;
|
||||
|
||||
var delta = viewportCenter - contentCenter;
|
||||
|
||||
var position = _content.anchoredPosition;
|
||||
position.y += delta;
|
||||
position.y += delta;
|
||||
_content.anchoredPosition = position;
|
||||
}
|
||||
|
||||
@@ -222,13 +206,13 @@ namespace BriarQueen.UI.Menus
|
||||
|
||||
first.GetWorldCorners(Corners);
|
||||
|
||||
var childTop = _viewport.InverseTransformPoint(Corners[1]).y;
|
||||
var childTop = _viewport.InverseTransformPoint(Corners[1]).y;
|
||||
var targetTop = _viewport.rect.yMax - _topInset;
|
||||
|
||||
var delta = targetTop - childTop;
|
||||
|
||||
var position = _content.anchoredPosition;
|
||||
position.y += delta;
|
||||
position.y += delta;
|
||||
_content.anchoredPosition = position;
|
||||
}
|
||||
|
||||
@@ -238,7 +222,7 @@ namespace BriarQueen.UI.Menus
|
||||
return;
|
||||
|
||||
var current = Normalized * _scrollRange;
|
||||
var next = Mathf.Clamp(current + pixels, 0f, _scrollRange);
|
||||
var next = Mathf.Clamp(current + pixels, 0f, _scrollRange);
|
||||
|
||||
Normalized = _scrollRange > 0f ? next / _scrollRange : 0f;
|
||||
SetNormalized(Normalized);
|
||||
@@ -258,7 +242,7 @@ namespace BriarQueen.UI.Menus
|
||||
var min = _trackRect.rect.yMin + halfHandleHeight;
|
||||
var max = _trackRect.rect.yMax - halfHandleHeight;
|
||||
|
||||
var y = Mathf.Clamp(localPoint.y, min, max);
|
||||
var y = Mathf.Clamp(localPoint.y, min, max);
|
||||
var normalized = 1f - Mathf.InverseLerp(min, max, y);
|
||||
|
||||
SetNormalized(normalized);
|
||||
@@ -284,8 +268,9 @@ namespace BriarQueen.UI.Menus
|
||||
|
||||
private void SetContentY(float y)
|
||||
{
|
||||
Debug.Log($"[Scrollbar] SetContentY:{y}");
|
||||
var position = _content.anchoredPosition;
|
||||
position.y = y;
|
||||
position.y = y;
|
||||
_content.anchoredPosition = position;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
@@ -308,22 +293,15 @@ namespace BriarQueen.UI.Menus
|
||||
return;
|
||||
}
|
||||
|
||||
if (_useCustomHandleSizing)
|
||||
{
|
||||
var ratio = Mathf.Clamp01(_viewport.rect.height / (_scrollRange + _viewport.rect.height));
|
||||
var height = Mathf.Max(_trackRect.rect.height * ratio, _minHandleHeight);
|
||||
_handleRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
|
||||
}
|
||||
|
||||
var half = _handleRect.rect.height * 0.5f;
|
||||
var min = _trackRect.rect.yMin + half;
|
||||
var max = _trackRect.rect.yMax - half;
|
||||
var yPos = Mathf.Lerp(max, min, Normalized);
|
||||
|
||||
var min = _trackRect.rect.yMin + half;
|
||||
var max = _trackRect.rect.yMax - half;
|
||||
|
||||
var y = Mathf.Lerp(max, min, Normalized);
|
||||
Debug.Log($"[Scrollbar] UpdateHandle — half:{half} trackYMin:{_trackRect.rect.yMin} trackYMax:{_trackRect.rect.yMax} min:{min} max:{max} yPos:{yPos} Normalized:{Normalized}");
|
||||
|
||||
var position = _handleRect.anchoredPosition;
|
||||
position.y = y;
|
||||
position.y = yPos;
|
||||
_handleRect.anchoredPosition = position;
|
||||
}
|
||||
|
||||
@@ -341,7 +319,7 @@ namespace BriarQueen.UI.Menus
|
||||
|
||||
private bool TryGetContentBounds(out float top, out float bottom)
|
||||
{
|
||||
top = float.MinValue;
|
||||
top = float.MinValue;
|
||||
bottom = float.MaxValue;
|
||||
|
||||
var found = false;
|
||||
@@ -357,13 +335,15 @@ namespace BriarQueen.UI.Menus
|
||||
for (var c = 0; c < 4; c++)
|
||||
{
|
||||
var local = _viewport.InverseTransformPoint(Corners[c]);
|
||||
top = Mathf.Max(top, local.y);
|
||||
top = Mathf.Max(top, local.y);
|
||||
bottom = Mathf.Min(bottom, local.y);
|
||||
}
|
||||
|
||||
found = true;
|
||||
Debug.Log($"[Scrollbar] Child: {child.name} top:{top} bottom:{bottom} height:{top - bottom}");
|
||||
}
|
||||
|
||||
Debug.Log($"[Scrollbar] Found:{found} ContentHeight:{top - bottom} ViewportHeight:{_viewport.rect.height}");
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user