void Update() { if (_Adapter == null) { return; } float pullAmount01 = 0f; var piv = _SrollbarPivotOnInit; int sign = 1; if (_Adapter.GetContentSizeToViewportRatio() > 1d) { var insetStart = _Adapter.ContentVirtualInsetFromViewportStart; if (insetStart > 0d) { if (_Adapter.IsHorizontal) { pullAmount01 = (float)(insetStart / _Adapter.BaseParameters.Viewport.rect.width); piv.x = 0f; } else { pullAmount01 = (float)(insetStart / _Adapter.BaseParameters.Viewport.rect.height); piv.y = 1f; } } else { var insetEnd = _Adapter.ContentVirtualInsetFromViewportEnd; if (insetEnd > 0d) { sign = -1; pullAmount01 = (float)(insetEnd / _Adapter.GetContentSize()); if (_Adapter.IsHorizontal) { pullAmount01 = (float)(insetEnd / _Adapter.BaseParameters.Viewport.rect.width); piv.x = 1f; } else { pullAmount01 = (float)(insetEnd / _Adapter.BaseParameters.Viewport.rect.height); piv.y = 0f; } } } } if (_HandleRT.pivot != piv) { _HandleRT.pivot = piv; } var euler = _HandleRT.localEulerAngles; // Multiplying argument by _Speed to speed up sine function growth euler.z = Mathf.Sin(pullAmount01 * _RotationSensivity * Mathf.PI) * _DegreesOfFreedom * sign; _HandleRT.localEulerAngles = euler; }
void OSAScrollPositionChanged(double scrollPos) { // The terms 'before' and 'after' mean what they should, if _InsetEdge is START, // but their meaning is swapped when _InsetEdge is END. var li = _OSA.GetLayoutInfoReadonly(); double osaInsetFromEdge; RectTransform.Edge edgeToInsetFrom; if (_InsetEdge == InsetEdgeEnum.START) { osaInsetFromEdge = _OSA.ContentVirtualInsetFromViewportStart; edgeToInsetFrom = li.startEdge; } else { osaInsetFromEdge = _OSA.ContentVirtualInsetFromViewportEnd; edgeToInsetFrom = li.endEdge; } double myExpectedInsetFromVirtualContent = _Inset; var rect = _RT.rect; double mySize = rect.size[li.hor0_vert1]; double osaViewportSize = li.vpSize; if (_InsetIsNormalized) { myExpectedInsetFromVirtualContent *= _OSA.GetContentSize() - mySize; } double myExpectedInsetFromViewport = osaInsetFromEdge + myExpectedInsetFromVirtualContent; bool visible = true; if (myExpectedInsetFromViewport < 0d) { if (myExpectedInsetFromViewport <= -mySize) // completely 'before' the viewport { myExpectedInsetFromViewport = -mySize; // don't position it too far away visible = false; } } else { if (myExpectedInsetFromViewport >= osaViewportSize) // completely 'after' the viewport { myExpectedInsetFromViewport = osaViewportSize; // don't position it too far away visible = false; } } bool disable = false; if (!visible) { disable = _DisableWhenNotVisible; } if (gameObject.activeSelf == disable) { gameObject.SetActive(!disable); } if (disable) { // No need to position it, since it's disabled now return; } if (!_AffectedByElasticity) { if (myExpectedInsetFromViewport > 0d) { // Update: actually, it looks better to just keep it at the edge, no matter what // // only if the content is bigger than viewport, otherwise the decorator is forced to stay with the content //if (_OSA.GetContentSizeToViewportRatio() > 1d) //{ //} myExpectedInsetFromViewport = 0d; } } _RT.SetInsetAndSizeFromParentEdgeWithCurrentAnchors(edgeToInsetFrom, (float)myExpectedInsetFromViewport, (float)mySize); }