fzhangtj
6 年前
当前提交
8e31db86
共有 12 个文件被更改,包括 666 次插入 和 78 次删除
-
23README.md
-
67Runtime/engine/WidgetCanvas.cs
-
3Runtime/foundation/basic_types.cs
-
4Runtime/ui/matrix.cs
-
19Runtime/ui/painting/canvas_impl.cs
-
60Runtime/ui/painting/canvas_shader.cs
-
2Runtime/ui/painting/path.cs
-
20Runtime/ui/painting/shader.cs
-
47Runtime/engine/input_utils.cs
-
11Runtime/engine/input_utils.cs.meta
-
465Tests/Resources/MaterialIcons-Regular.ttf
-
23Tests/Resources/MaterialIcons-Regular.ttf.meta
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using UnityEngine.EventSystems; |
|||
|
|||
namespace Unity.UIWidgets.engine { |
|||
static class InputUtils { |
|||
const int mouseScrollId = 1; |
|||
const int preservedKeyNum = 10; |
|||
const int preservedMouseKeyNum = 100; |
|||
const int fingerKeyStart = preservedKeyNum + preservedMouseKeyNum; |
|||
|
|||
public static PointerDeviceKind getPointerDeviceKind(PointerEventData eventData) { |
|||
return isTouchEvent(eventData) ? PointerDeviceKind.touch : PointerDeviceKind.mouse; |
|||
} |
|||
|
|||
public static int getPointerDeviceKey(PointerEventData eventData) { |
|||
return isTouchEvent(eventData) |
|||
? getTouchFingerKey(eventData.pointerId) |
|||
: getMouseButtonKey((int) eventData.button); |
|||
} |
|||
|
|||
public static int getScrollButtonKey() { |
|||
return mouseScrollId; |
|||
} |
|||
|
|||
public static int getMouseButtonKey(int buttonId) { |
|||
D.assert(buttonId < preservedMouseKeyNum); |
|||
return buttonId + preservedKeyNum; |
|||
} |
|||
|
|||
static int getTouchFingerKey(int fingerId) { |
|||
return fingerId + fingerKeyStart; |
|||
} |
|||
|
|||
static bool isTouchEvent(PointerEventData eventData) { |
|||
//pointerId >= 0 : touches
|
|||
//ref: https://docs.unity3d.com/ScriptReference/EventSystems.PointerEventData-pointerId.html
|
|||
return eventData.pointerId >= 0; |
|||
} |
|||
|
|||
static bool isMouseEvent(PointerEventData eventData) { |
|||
//pointerId = -1, -2, -3 : mouse buttons
|
|||
//ref: https://docs.unity3d.com/ScriptReference/EventSystems.PointerEventData-pointerId.html
|
|||
return eventData.pointerId < 0; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 59b547839c038453d82019f8bef7d407 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
|