Update Cryville.Input.

This commit is contained in:
2023-05-07 13:42:53 +08:00
parent fa9303c0a1
commit bd028c1b72
17 changed files with 1336 additions and 579 deletions

View File

@@ -1,23 +1,32 @@
using Cryville.Common.Interop;
using Cryville.Common.Logging;
using System;
namespace Cryville.Input.Unity.Android {
public class AndroidTouchHandler : AndroidInputHandler<AndroidTouchHandler> {
/// <summary>
/// An <see cref="InputHandler" /> that handles Android touch input.
/// </summary>
public class AndroidTouchHandler : AndroidInputHandler {
/// <summary>
/// Creates an instance of the <see cref="AndroidTouchHandler" /> class.
/// </summary>
public AndroidTouchHandler() : base("world/cryville/input/unity/android/TouchProxy") { }
/// <inheritdoc />
public override bool IsNullable => true;
/// <inheritdoc />
public override byte Dimension => 2;
readonly static ReferenceCue _refCue = new ReferenceCue {
static readonly ReferenceCue _refCue = new ReferenceCue {
PhysicalDimension = new PhysicalDimension { Length = 1 },
RelativeUnit = RelativeUnit.Pixel,
Flags = ReferenceFlag.FlipY,
Pivot = new InputVector(0, 1),
};
/// <inheritdoc />
public override ReferenceCue ReferenceCue => _refCue;
/// <inheritdoc />
public override string GetTypeName(int type) {
switch (type) {
case 0: return "Android Touch";
@@ -25,19 +34,17 @@ namespace Cryville.Input.Unity.Android {
}
}
/// <inheritdoc />
public override double GetCurrentTimestamp() {
return JavaStaticMethods.SystemClock_uptimeMillis() / 1000.0;
}
private protected override AndroidInputProxy_Callback Callback { get { return OnFeed; } }
[MonoPInvokeCallback]
static void OnFeed(int id, int action, long time, float x, float y, float z, float w) {
internal override void OnFeed(int id, int action, long time, float x, float y, float z, float w) {
try {
double timeSecs = time / 1000.0;
Instance.Feed(0, id, new InputFrame(timeSecs, new InputVector(x, y)));
Feed(0, id, new InputFrame(timeSecs, new InputVector(x, y)));
if (action == 1 /*ACTION_UP*/ || action == 3 /*ACTION_CANCEL*/ || action == 6 /*ACTION_POINTER_UP*/)
Instance.Feed(0, id, new InputFrame(timeSecs));
Feed(0, id, new InputFrame(timeSecs));
}
catch (Exception ex) {
Logger.Log("main", 4, "Input", "An error occurred while handling an Android touch event: {0}", ex);