浏览代码
Merge branch 'material' into 'master'
Merge branch 'material' into 'master'
Mouse scroll bug fix See merge request upm-packages/ui-widgets/com.unity.uiwidgets!57/main
Shenhua Gu
6 年前
当前提交
514b30d1
共有 8 个文件被更改,包括 158 次插入 和 35 次删除
-
40Runtime/editor/editor_window.cs
-
23Runtime/engine/WidgetCanvas.cs
-
8Runtime/gestures/binding.cs
-
16Runtime/gestures/monodrag.cs
-
2Runtime/ui/txt/paragraph.cs
-
12Runtime/widgets/sliver.cs
-
81Runtime/editor/scroll_input.cs
-
11Runtime/editor/scroll_input.cs.meta
|
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.editor { |
|||
public class ScrollInput { |
|||
readonly int _bufferSize = 10; |
|||
readonly float _scrollScale = 10; |
|||
|
|||
float _scrollDeltaX; |
|||
float _scrollDeltaY; |
|||
|
|||
int _bufferIndex; |
|||
float _curDeltaX; |
|||
float _curDeltaY; |
|||
|
|||
float _pointerX; |
|||
float _pointerY; |
|||
int _buttonId; |
|||
|
|||
public ScrollInput(int bufferSize = 10, float scrollScale = 10) { |
|||
this._bufferIndex = bufferSize; |
|||
this._bufferSize = bufferSize; |
|||
this._scrollDeltaX = 0; |
|||
this._scrollDeltaY = 0; |
|||
this._curDeltaX = 0; |
|||
this._curDeltaY = 0; |
|||
this._scrollScale = scrollScale; |
|||
} |
|||
|
|||
public void onScroll(float deltaX, float deltaY, float pointerX, float pointerY, int buttonId) { |
|||
this._scrollDeltaX += deltaX * this._scrollScale; |
|||
this._scrollDeltaY += deltaY * this._scrollScale; |
|||
this._bufferIndex = this._bufferSize; |
|||
this._curDeltaX = this._scrollDeltaX / this._bufferIndex; |
|||
this._curDeltaY = this._scrollDeltaY / this._bufferIndex; |
|||
|
|||
this._pointerX = pointerX; |
|||
this._pointerY = pointerY; |
|||
this._buttonId = buttonId; |
|||
} |
|||
|
|||
public int getDeviceId() { |
|||
return this._buttonId; |
|||
} |
|||
|
|||
public float getPointerPosX() { |
|||
return this._pointerX; |
|||
} |
|||
|
|||
public float getPointerPosY() { |
|||
return this._pointerY; |
|||
} |
|||
|
|||
public Vector2 getScrollDelta() { |
|||
if (this._scrollDeltaX == 0 && this._scrollDeltaY == 0) { |
|||
return Vector2.zero; |
|||
} |
|||
|
|||
var deltaScroll = new Vector2(); |
|||
if (this._bufferIndex == 0) { |
|||
deltaScroll.x = this._scrollDeltaX; |
|||
deltaScroll.y = this._scrollDeltaY; |
|||
this._scrollDeltaX = 0; |
|||
this._scrollDeltaY = 0; |
|||
} |
|||
else { |
|||
deltaScroll.x = this._curDeltaX; |
|||
deltaScroll.y = this._curDeltaY; |
|||
this._scrollDeltaX = this._curDeltaX > 0 |
|||
? Math.Max(0, this._scrollDeltaX - this._curDeltaX) |
|||
: Math.Min(0, this._scrollDeltaX - this._curDeltaX); |
|||
this._scrollDeltaY = this._curDeltaY > 0 |
|||
? Math.Max(0, this._scrollDeltaY - this._curDeltaY) |
|||
: Math.Min(0, this._scrollDeltaY - this._curDeltaY); |
|||
this._bufferIndex--; |
|||
} |
|||
|
|||
return deltaScroll; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 492cc1893411b4b5085b8db85e96ca5b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue