Update Cryville.Input.
This commit is contained in:
@@ -3,40 +3,54 @@ using UnityEngine;
|
||||
using unity = UnityEngine;
|
||||
|
||||
namespace Cryville.Input.Unity {
|
||||
/// <summary>
|
||||
/// An <see cref="InputHandler" /> that handles Unity touch input.
|
||||
/// </summary>
|
||||
public class UnityTouchHandler : InputHandler {
|
||||
GameObject _receiver;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="UnityTouchHandler" /> class.
|
||||
/// </summary>
|
||||
/// <exception cref="NotSupportedException">Unity touch is not supported on the current device.</exception>
|
||||
public UnityTouchHandler() {
|
||||
if (!unity::Input.touchSupported) {
|
||||
throw new NotSupportedException("Unity touch is not supported on this device");
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Activate() {
|
||||
_receiver = new GameObject("__touchRecv__");
|
||||
_receiver.AddComponent<UnityPointerReceiver>().SetHandler(this);
|
||||
_receiver.AddComponent<UnityTouchReceiver>().SetHandler(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Deactivate() {
|
||||
if (_receiver) GameObject.Destroy(_receiver);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsNullable { get { return true; } }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override byte Dimension { get { return 2; } }
|
||||
|
||||
readonly static ReferenceCue _refCue = new ReferenceCue {
|
||||
static readonly ReferenceCue _refCue = new ReferenceCue {
|
||||
PhysicalDimension = new PhysicalDimension { Length = 1 },
|
||||
RelativeUnit = RelativeUnit.Pixel,
|
||||
};
|
||||
/// <inheritdoc />
|
||||
public override ReferenceCue ReferenceCue => _refCue;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetTypeName(int type) {
|
||||
switch (type) {
|
||||
case 0: return "Touch";
|
||||
@@ -44,12 +58,20 @@ namespace Cryville.Input.Unity {
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetCurrentTimestamp() {
|
||||
return Time.realtimeSinceStartupAsDouble;
|
||||
}
|
||||
|
||||
public class UnityPointerReceiver : MonoBehaviour {
|
||||
/// <summary>
|
||||
/// Unity touch receiver.
|
||||
/// </summary>
|
||||
public class UnityTouchReceiver : MonoBehaviour {
|
||||
UnityTouchHandler _handler;
|
||||
/// <summary>
|
||||
/// Sets the <see cref="UnityTouchHandler" />.
|
||||
/// </summary>
|
||||
/// <param name="h">The <see cref="UnityTouchHandler" />.</param>
|
||||
public void SetHandler(UnityTouchHandler h) {
|
||||
_handler = h;
|
||||
}
|
||||
|
Reference in New Issue
Block a user