using System; using UnityEngine; namespace Cryville.Input.Unity.Android { /// /// An that handles Android input. /// public abstract class AndroidInputHandler : InputHandler { readonly IntPtr _t_T; static readonly jvalue[] _p_void = new jvalue[0]; readonly IntPtr _i_T; readonly IntPtr _m_T_activate; readonly IntPtr _m_T_deactivate; bool _activated; /// /// Creates an instance of the class. /// /// The full name of the Java class that performs the low-level jobs. /// An instance of this class have already been created. /// Android input is not supported on the current device. public AndroidInputHandler(string className) { if (Environment.OSVersion.Platform != PlatformID.Unix) throw new NotSupportedException("Android input is not supported on this device"); JavaStaticMethods.Init(); var _lt_T = AndroidJNI.FindClass(className); _t_T = AndroidJNI.NewGlobalRef(_lt_T); AndroidJNI.DeleteLocalRef(_lt_T); var _m_T_init = AndroidJNI.GetMethodID(_t_T, "", "()V"); var _li_T = AndroidJNI.NewObject(_t_T, _m_T_init, _p_void); _i_T = AndroidJNI.NewGlobalRef(_li_T); AndroidJNI.DeleteLocalRef(_li_T); var _m_T_getId = AndroidJNI.GetMethodID(_t_T, "getId", "()I"); _m_T_activate = AndroidJNI.GetMethodID(_t_T, "activate", "()V"); _m_T_deactivate = AndroidJNI.GetMethodID(_t_T, "deactivate", "()V"); AndroidInputPoller.Instance.Register(AndroidJNI.CallIntMethod(_i_T, _m_T_getId, _p_void), this); } /// protected override void Activate() { if (_activated) return; _activated = true; AndroidJNI.CallVoidMethod(_i_T, _m_T_activate, _p_void); } /// protected override void Deactivate() { if (!_activated) return; _activated = false; AndroidJNI.CallVoidMethod(_i_T, _m_T_deactivate, _p_void); } /// public override void Dispose(bool disposing) { if (disposing) { Deactivate(); AndroidJNI.DeleteGlobalRef(_i_T); AndroidJNI.DeleteGlobalRef(_t_T); } } internal abstract void OnFeed(int id, int action, long time, float x, float y, float z, float w); } }