Update Cryville.Input. Fix cleanup logic for input proxy.
This commit is contained in:
@@ -42,6 +42,7 @@ namespace Cryville.Input.Unity.Android {
|
||||
try {
|
||||
double timeSecs = time / 1e9;
|
||||
Feed(0, id, new InputFrame(timeSecs, new InputVector(x, y, z, w)));
|
||||
Batch(timeSecs);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Log("main", 4, "Input", "An error occurred while handling an Android sensor event: {0}", ex);
|
||||
|
@@ -42,9 +42,14 @@ namespace Cryville.Input.Unity.Android {
|
||||
internal override void OnFeed(int id, int action, long time, float x, float y, float z, float w) {
|
||||
try {
|
||||
double timeSecs = time / 1000.0;
|
||||
Feed(0, id, new InputFrame(timeSecs, new InputVector(x, y)));
|
||||
if (action == 1 /*ACTION_UP*/ || action == 3 /*ACTION_CANCEL*/ || action == 6 /*ACTION_POINTER_UP*/)
|
||||
Feed(0, id, new InputFrame(timeSecs));
|
||||
if (action == -2) {
|
||||
Batch(timeSecs);
|
||||
}
|
||||
else {
|
||||
Feed(0, id, new InputFrame(timeSecs, new InputVector(x, y)));
|
||||
if (action == 1 /*ACTION_UP*/ || action == 3 /*ACTION_CANCEL*/ || action == 6 /*ACTION_POINTER_UP*/)
|
||||
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);
|
||||
|
@@ -44,6 +44,7 @@ public final class TouchProxy extends Proxy implements View.OnTouchListener {
|
||||
feed(id, action, time, x, y);
|
||||
}
|
||||
}
|
||||
feed(0, -2, time);
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -20,7 +20,8 @@ namespace Cryville.Input.Unity {
|
||||
protected override void Activate() {
|
||||
_receiver = new GameObject("__guiRecv__");
|
||||
_recvComp = _receiver.AddComponent<T>();
|
||||
_recvComp.SetCallback(Feed);
|
||||
_recvComp.SetFeedCallback(Feed);
|
||||
_recvComp.SetBatchCallback(Batch);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -63,19 +64,30 @@ namespace Cryville.Input.Unity {
|
||||
/// <summary>
|
||||
/// The callback function to be called when a new input frame is received.
|
||||
/// </summary>
|
||||
protected Action<int, int, InputFrame> Callback;
|
||||
/// <summary>
|
||||
/// The set of currently active keys.
|
||||
/// </summary>
|
||||
protected readonly HashSet<int> ActiveKeys = new HashSet<int>();
|
||||
protected Action<int, int, InputFrame> Feed;
|
||||
/// <summary>
|
||||
/// Sets the callback function to be called when a new input frame is received.
|
||||
/// </summary>
|
||||
/// <param name="h">The callback function to be called when a new input frame is received.</param>
|
||||
public void SetCallback(Action<int, int, InputFrame> h) {
|
||||
Callback = h;
|
||||
public void SetFeedCallback(Action<int, int, InputFrame> h) {
|
||||
Feed = h;
|
||||
}
|
||||
/// <summary>
|
||||
/// The callback function to be called when the current input batch is finished receiving.
|
||||
/// </summary>
|
||||
protected Action<double> Batch;
|
||||
/// <summary>
|
||||
/// Sets the callback function to be called when the current input batch is finished receiving.
|
||||
/// </summary>
|
||||
/// <param name="h">The callback function to be called when the current input batch is finished receiving.</param>
|
||||
public void SetBatchCallback(Action<double> h) {
|
||||
Batch = h;
|
||||
}
|
||||
/// <summary>
|
||||
/// The set of currently active keys.
|
||||
/// </summary>
|
||||
protected readonly HashSet<int> ActiveKeys = new HashSet<int>();
|
||||
/// <summary>
|
||||
/// Gets the friendly name of the specified key.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
@@ -87,8 +99,9 @@ namespace Cryville.Input.Unity {
|
||||
void Update() {
|
||||
double time = Time.realtimeSinceStartupAsDouble;
|
||||
foreach (var k in ActiveKeys) {
|
||||
Callback(k, 0, new InputFrame(time, new InputVector()));
|
||||
Feed(k, 0, new InputFrame(time, new InputVector()));
|
||||
}
|
||||
Batch(time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,13 +118,13 @@ namespace Cryville.Input.Unity {
|
||||
switch (e.type) {
|
||||
case EventType.KeyDown:
|
||||
if (!ActiveKeys.Contains(key)) {
|
||||
Callback(key, 0, new InputFrame(time, new InputVector()));
|
||||
Feed(key, 0, new InputFrame(time, new InputVector()));
|
||||
ActiveKeys.Add(key);
|
||||
}
|
||||
break;
|
||||
case EventType.KeyUp:
|
||||
ActiveKeys.Remove(key);
|
||||
Callback(key, 0, new InputFrame(time));
|
||||
Feed(key, 0, new InputFrame(time));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -134,13 +147,13 @@ namespace Cryville.Input.Unity {
|
||||
switch (e.type) {
|
||||
case EventType.MouseDown:
|
||||
if (!ActiveKeys.Contains(key)) {
|
||||
Callback(key, 0, new InputFrame(time, new InputVector()));
|
||||
Feed(key, 0, new InputFrame(time, new InputVector()));
|
||||
ActiveKeys.Add(key);
|
||||
}
|
||||
break;
|
||||
case EventType.MouseUp:
|
||||
ActiveKeys.Remove(key);
|
||||
Callback(key, 0, new InputFrame(time));
|
||||
Feed(key, 0, new InputFrame(time));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -79,6 +79,7 @@ namespace Cryville.Input.Unity {
|
||||
double time = Time.realtimeSinceStartupAsDouble;
|
||||
Vector3 pos = unity::Input.mousePosition;
|
||||
_handler.Feed(0, 0, new InputFrame(time, new InputVector(pos.x, pos.y)));
|
||||
_handler.Batch(time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -86,6 +86,7 @@ namespace Cryville.Input.Unity {
|
||||
_handler.Feed(0, t.fingerId, new InputFrame(time));
|
||||
}
|
||||
}
|
||||
_handler.Batch(time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@@ -34,6 +34,13 @@
|
||||
<param name="identifier">The input identifier of <paramref name="frame" />.</param>
|
||||
<param name="frame">The new input frame.</param>
|
||||
</member>
|
||||
<member name="T:Cryville.Input.InputBatchHandler">
|
||||
<summary>
|
||||
Represents the method that will handle the <see cref="E:Cryville.Input.InputHandler.OnBatch" /> event.
|
||||
</summary>
|
||||
<param name="handler">The input handler.</param>
|
||||
<param name="time">The timestamp of the batch in seconds.</param>
|
||||
</member>
|
||||
<member name="T:Cryville.Input.InputHandler">
|
||||
<summary>
|
||||
Input handler.
|
||||
@@ -44,6 +51,11 @@
|
||||
Occurs when a new input frame is sent.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="E:Cryville.Input.InputHandler.OnBatch">
|
||||
<summary>
|
||||
Occurs when an input batch is finished sending.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Cryville.Input.InputHandler.Finalize">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
@@ -114,6 +126,12 @@
|
||||
<param name="id">The ID of the input frame.</param>
|
||||
<param name="frame">The input frame.</param>
|
||||
</member>
|
||||
<member name="M:Cryville.Input.InputHandler.Batch(System.Double)">
|
||||
<summary>
|
||||
Marks the end of the current input batch and starts a new batch.
|
||||
</summary>
|
||||
<param name="time">The timestamp of the input batch in seconds.</param>
|
||||
</member>
|
||||
<member name="T:Cryville.Input.InputIdentifier">
|
||||
<summary>
|
||||
Input identifier.
|
||||
|
@@ -36,6 +36,13 @@
|
||||
</param>
|
||||
<param name="frame">新的输入帧。</param>
|
||||
</member>
|
||||
<member name="T:Cryville.Input.InputBatchHandler">
|
||||
<summary>
|
||||
表示处理 <see cref="E:Cryville.Input.InputHandler.OnBatch" /> 事件的方法。
|
||||
</summary>
|
||||
<param name="handler">输入处理器。</param>
|
||||
<param name="time">输入批次的时间戳(秒)。</param>
|
||||
</member>
|
||||
<member name="T:Cryville.Input.InputHandler">
|
||||
<summary>
|
||||
输入处理器。
|
||||
@@ -46,6 +53,11 @@
|
||||
在新的输入帧被发送时发生。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="E:Cryville.Input.InputHandler.OnBatch">
|
||||
<summary>
|
||||
在输入批次完成发送时发生。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Cryville.Input.InputHandler.Finalize">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
@@ -124,6 +136,12 @@
|
||||
<param name="id">输入帧的 ID。</param>
|
||||
<param name="frame">输入帧。</param>
|
||||
</member>
|
||||
<member name="M:Cryville.Input.InputHandler.Batch(System.Double)">
|
||||
<summary>
|
||||
将当前的输入批次标记结束并开始新的批次。
|
||||
</summary>
|
||||
<param name="time">输入批次的时间戳(秒)。</param>
|
||||
</member>
|
||||
<member name="T:Cryville.Input.InputIdentifier">
|
||||
<summary>
|
||||
输入标识。
|
||||
|
Reference in New Issue
Block a user