You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.EventSystems;
  6. using System.Runtime.InteropServices;
  7. using System;
  8. public class WebGLKeyboard : MonoBehaviour, ISelectHandler
  9. {
  10. [DllImport("__Internal")]
  11. private static extern void focusHandleAction(string _name, string _str);
  12. private InputField UnityInput;
  13. private TMPro.TMP_InputField TMPInput;
  14. private void Awake()
  15. {
  16. UnityInput = GetComponent<InputField>();
  17. TMPInput = GetComponent<TMPro.TMP_InputField>();
  18. }
  19. public void ReceiveInputData(string value)
  20. {
  21. if (TMPInput != null)
  22. TMPInput.text = value;
  23. else if (UnityInput != null)
  24. UnityInput.text = value;
  25. }
  26. public void OnSelect(BaseEventData data)
  27. {
  28. #if UNITY_WEBGL
  29. try
  30. {
  31. if (TMPInput != null)
  32. focusHandleAction(gameObject.name, TMPInput.text);
  33. else if (UnityInput != null)
  34. focusHandleAction(gameObject.name, UnityInput.text);
  35. }
  36. catch (Exception error) { }
  37. #endif
  38. }
  39. }