Create a gist now

Instantly share code, notes, and snippets.

UnityでWindowsデスクトップアプリの仮想キーボードをハンドリングするスクリプト
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityKeyboard;
public class KeyboardManager : MonoBehaviour
{
GameObject currentSelectable;
void Update()
{
if (EventSystem.current.currentSelectedGameObject.Equals(currentSelectable))
{
return;
}
if (EventSystem.current.currentSelectedGameObject == null
|| !EventSystem.current.currentSelectedGameObject.activeInHierarchy)
{
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
TouchKeyboard.Close();
#endif
return;
}
currentSelectable = EventSystem.current.currentSelectedGameObject;
if (currentSelectable.GetComponent<InputField>() != null)
{
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
TouchKeyboard.Open();
#endif
}
else
{
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
TouchKeyboard.Close();
#endif
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment