Tanoda
WebGLInputMobile.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
5using System.Runtime.InteropServices; // for DllImport
6using AOT;
7using System;
8
9namespace WebGLSupport
10{
12 {
13#if UNITY_WEBGL && !UNITY_EDITOR
14 [DllImport("__Internal")]
15 public static extern int WebGLInputMobileRegister(Action<int> OnTouchEnd);
16
17 [DllImport("__Internal")]
18 public static extern void WebGLInputMobileOnFocusOut(int id, Action<int> OnFocusOut);
19#else
24 public static int WebGLInputMobileRegister(Action<int> OnTouchEnd) { return 0; }
25
26 public static void WebGLInputMobileOnFocusOut(int id, Action<int> OnFocusOut) {}
27#endif
28 }
29
30 public class WebGLInputMobile : MonoBehaviour, IPointerDownHandler
31 {
32 static Dictionary<int, WebGLInputMobile> instances = new Dictionary<int, WebGLInputMobile>();
33
34 int id = -1;
35
36 private void Awake()
37 {
38#if !(UNITY_WEBGL && !UNITY_EDITOR)
39 // WebGL 以外、更新メソッドは動作しないようにします
40 enabled = false;
41#endif
42 }
43
48 public void OnPointerDown(PointerEventData eventData)
49 {
50 if (id != -1) return;
52 instances[id] = this;
53 }
54
55 [MonoPInvokeCallback(typeof(Action<int>))]
56 static void OnTouchEnd(int id)
57 {
58 var @this = instances[id];
59 @this.GetComponent<WebGLInput>().OnSelect();
60 @this.StartCoroutine(RegisterOnFocusOut(id));
61 }
62
63 static IEnumerator RegisterOnFocusOut(int id)
64 {
65 yield return null; // wait one frame.
66 WebGLInputMobilePlugin.WebGLInputMobileOnFocusOut(id, OnFocusOut);
67 }
68
69 [MonoPInvokeCallback(typeof(Action<int>))]
70 static void OnFocusOut(int id)
71 {
72 Debug.Log(string.Format("OnFocusOut:{0}", id));
73 var @this = instances[id];
74 @this.GetComponent<WebGLInput>().DeactivateInputField();
75 // release
76 @this.id = -1;
77 instances.Remove(id);
78 }
79 }
80}
81
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void OnPointerDown(PointerEventData eventData)
押されたら、touchend イベントを登録する
static void WebGLInputMobileOnFocusOut(int id, Action< int > OnFocusOut)
static int WebGLInputMobileRegister(Action< int > OnTouchEnd)
ID を割り振り