|
|
|
|
|
|
|
|
|
|
namespace Unity.UIWidgets.editor { |
|
|
|
public class ScrollInput { |
|
|
|
readonly int _bufferSize = 20; |
|
|
|
readonly float _scrollScale = 10; |
|
|
|
readonly float _bufferSize = 20.0f / 60; // a scroll action leads to 20 frames, i.e., ( 20 / 60 ) seconds smoothly-scrolling when fps = 60 (default)
|
|
|
|
readonly float _scrollScale = 20; |
|
|
|
int _bufferIndex; |
|
|
|
float _bufferIndex; |
|
|
|
float _curDeltaX; |
|
|
|
float _curDeltaY; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ScrollInput(int? bufferSize = null, float? scrollScale = null) { |
|
|
|
public ScrollInput(float? bufferSize = null, float? scrollScale = null) { |
|
|
|
this._bufferSize = bufferSize ?? this._bufferSize; |
|
|
|
this._scrollScale = scrollScale ?? this._scrollScale; |
|
|
|
|
|
|
|
|
|
|
return this._pointerY; |
|
|
|
} |
|
|
|
|
|
|
|
public Vector2 getScrollDelta() { |
|
|
|
public Vector2 getScrollDelta(float deltaTime) { |
|
|
|
if (this._bufferIndex == 0) { |
|
|
|
if (this._bufferIndex <= deltaTime) { |
|
|
|
deltaScroll.x = this._scrollDeltaX; |
|
|
|
deltaScroll.y = this._scrollDeltaY; |
|
|
|
this._scrollDeltaX = 0; |
|
|
|
|
|
|
deltaScroll.x = this._curDeltaX; |
|
|
|
deltaScroll.y = this._curDeltaY; |
|
|
|
deltaScroll.x = this._curDeltaX * deltaTime; |
|
|
|
deltaScroll.y = this._curDeltaY * deltaTime; |
|
|
|
? Mathf.Max(0, this._scrollDeltaX - this._curDeltaX) |
|
|
|
: Mathf.Min(0, this._scrollDeltaX - this._curDeltaX); |
|
|
|
? Mathf.Max(0, this._scrollDeltaX - this._curDeltaX * deltaTime) |
|
|
|
: Mathf.Min(0, this._scrollDeltaX - this._curDeltaX * deltaTime); |
|
|
|
? Mathf.Max(0, this._scrollDeltaY - this._curDeltaY) |
|
|
|
: Mathf.Min(0, this._scrollDeltaY - this._curDeltaY); |
|
|
|
this._bufferIndex--; |
|
|
|
? Mathf.Max(0, this._scrollDeltaY - this._curDeltaY * deltaTime) |
|
|
|
: Mathf.Min(0, this._scrollDeltaY - this._curDeltaY * deltaTime); |
|
|
|
this._bufferIndex -= deltaTime; |
|
|
|
|
|
|
|
|
|
|
|
return deltaScroll; |
|
|
|
} |
|
|
|
} |