Update Cryville.Input.
This commit is contained in:
@@ -2,9 +2,10 @@ using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Input.Unity.Android {
|
||||
public abstract class AndroidInputHandler<TSelf> : InputHandler where TSelf : AndroidInputHandler<TSelf> {
|
||||
protected static TSelf Instance { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="InputHandler" /> that handles Android input.
|
||||
/// </summary>
|
||||
public abstract class AndroidInputHandler : InputHandler {
|
||||
readonly IntPtr _t_T;
|
||||
static readonly jvalue[] _p_void = new jvalue[0];
|
||||
readonly IntPtr _i_T;
|
||||
@@ -14,12 +15,15 @@ namespace Cryville.Input.Unity.Android {
|
||||
|
||||
bool _activated;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="AndroidInputHandler{TSelf}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="className">The full name of the Java class that performs the low-level jobs.</param>
|
||||
/// <exception cref="InvalidOperationException">An instance of this class have already been created.</exception>
|
||||
/// <exception cref="NotSupportedException">Android input is not supported on the current device.</exception>
|
||||
public AndroidInputHandler(string className) {
|
||||
if (Instance != null)
|
||||
throw new InvalidOperationException("AndroidInputHandler already created");
|
||||
if (Environment.OSVersion.Platform != PlatformID.Unix)
|
||||
throw new NotSupportedException("Android input is not supported on this device");
|
||||
Instance = (TSelf)this;
|
||||
|
||||
JavaStaticMethods.Init();
|
||||
|
||||
@@ -36,24 +40,24 @@ namespace Cryville.Input.Unity.Android {
|
||||
_m_T_activate = AndroidJNI.GetMethodID(_t_T, "activate", "()V");
|
||||
_m_T_deactivate = AndroidJNI.GetMethodID(_t_T, "deactivate", "()V");
|
||||
|
||||
NativeMethods.AndroidInputProxy_RegisterCallback(
|
||||
AndroidJNI.CallIntMethod(_i_T, _m_T_getId, _p_void),
|
||||
Callback
|
||||
);
|
||||
AndroidInputPoller.Instance.Register(AndroidJNI.CallIntMethod(_i_T, _m_T_getId, _p_void), this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Activate() {
|
||||
if (_activated) return;
|
||||
_activated = true;
|
||||
AndroidJNI.CallVoidMethod(_i_T, _m_T_activate, _p_void);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Deactivate() {
|
||||
if (!_activated) return;
|
||||
_activated = false;
|
||||
AndroidJNI.CallVoidMethod(_i_T, _m_T_deactivate, _p_void);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Deactivate();
|
||||
@@ -62,6 +66,6 @@ namespace Cryville.Input.Unity.Android {
|
||||
}
|
||||
}
|
||||
|
||||
private protected abstract AndroidInputProxy_Callback Callback { get; }
|
||||
internal abstract void OnFeed(int id, int action, long time, float x, float y, float z, float w);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user