forked from dantasulisses/WebMobileInputFix
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDetectInputFocus.cs
More file actions
53 lines (51 loc) · 1.55 KB
/
Copy pathDetectInputFocus.cs
File metadata and controls
53 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
namespace WebGLKeyboard
{
/// <summary>
/// Trigger the focus event in input fields
/// </summary>
public class DetectInputFocus : MonoBehaviour, IPointerClickHandler, IDeselectHandler
{
private KeyboardController controller = null;
private UnityEngine.UI.InputField nativeInput;
#if TMP_PRESENT
private TMPro.TMP_InputField tmproInput;
#endif
public void Initialize(KeyboardController _controller)
{
controller = _controller;
nativeInput = gameObject.GetComponent<UnityEngine.UI.InputField>();
#if TMP_PRESENT
tmproInput = gameObject.GetComponent<TMPro.TMP_InputField>();
#endif
}
/// <summary>
/// Calls the controller passing the selected input field to enable the keyboard
/// </summary>
/// <param name="_data"></param>
public void OnPointerClick(PointerEventData _data)
{
if (nativeInput != null)
{
controller.FocusInput(nativeInput);
}
#if TMP_PRESENT
if (tmproInput != null)
{
controller.FocusInput(tmproInput);
}
#endif
}
/// <summary>
/// Clears the input action if the player deselected the field ingame
/// </summary>
/// <param name="data"></param>
public void OnDeselect(BaseEventData data)
{
controller.ForceClose();
}
}
}