Implement input proxy. Change input callback delegate to event. Prevents repeated (de)activation.

This commit is contained in:
2022-11-06 00:50:09 +08:00
parent 7f02b75b29
commit 8f98cb63cb
7 changed files with 119 additions and 111 deletions

View File

@@ -12,18 +12,18 @@ namespace Cryville.Common.Unity.Input {
}
}
public override void Activate() {
protected override void ActivateImpl() {
receiver = new GameObject("__touchrecv__");
receiver.AddComponent<UnityPointerReceiver>().SetHandler(this);
}
public override void Deactivate() {
protected override void DeactivateImpl() {
if (receiver) GameObject.Destroy(receiver);
}
public override void Dispose(bool disposing) {
if (disposing) {
Deactivate();
DeactivateImpl();
}
}
@@ -61,11 +61,11 @@ namespace Cryville.Common.Unity.Input {
pos.y = Screen.height - pos.y;
var vec = new InputVector(time, pos);
if (t.phase == TouchPhase.Began || t.phase == TouchPhase.Stationary || t.phase == TouchPhase.Moved) {
handler.OnInput(0, t.fingerId, vec);
handler.Feed(0, t.fingerId, vec);
}
else if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled) {
handler.OnInput(0, t.fingerId, vec);
handler.OnInput(0, t.fingerId, new InputVector(time));
handler.Feed(0, t.fingerId, vec);
handler.Feed(0, t.fingerId, new InputVector(time));
}
}
}