Help us understand the problem. What is going on with this article?

Unity 2017.x+InputField+Androidで日本語入力ができない問題への対策

More than 3 years have passed since last update.

Unity 2017.1 において Content Type を Standard 等にしていると、 Android 上で InputField から日本語入力できない(日本語入力に切り替えられない)というケースがあるようです(2017.2も試しましたが現時点では改善なしでした)。
こちらは InputField 経由でなく、自分で TouchScreenKeyboard.Open を用いてキーボードを呼びだすことで回避可能のようでした。
以下サンプルコードです。

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

/// <summary>
/// 2017.x を用いたバイナリが Android 上だとキーボードで日本語入力できない問題のワークアラウンド用.
/// InputField の子に Button を置き、その Button にアタッチして使用する.
/// </summary>
public class InputFieldButton : Button {

    private InputField inputField
    {
        get
        {
            if (inputField_ == null) {
                inputField_ = GetComponentInParent<InputField> ();
            }
            return inputField_;
        }
    }
    private InputField inputField_;

    private TouchScreenKeyboard keyboard_ = null;
    private string originalText_ = "";
    private bool wasCanceled_ = false;

    void CreateKeyboard()
    {
        if (keyboard_ != null) return;
        if (!IsInteractable ())    return;

        if (!inputField.textComponent || inputField.textComponent.font == null)
            return;

        originalText_ = inputField.text;
        keyboard_ = TouchScreenKeyboard.Open (inputField.text, TouchScreenKeyboardType.Default, true);
    }

    void DestroyKeyboard()
    {
        if (!inputField.textComponent || !inputField.IsInteractable ())
            return;            

        if (wasCanceled_) {
            inputField.text = originalText_;
            wasCanceled_ = false;
        }

        if (keyboard_ != null) {
            keyboard_.active = false;
            keyboard_ = null;
            originalText_ = "";
        }
    }

    void LateUpdate() {
        if (keyboard_ == null) return;

        inputField.text = keyboard_.text;

        if (keyboard_.wasCanceled) {
            wasCanceled_ = true;
            DestroyKeyboard ();
        }

        if (keyboard_.done) {
            DestroyKeyboard ();
        }
    }

    public override void OnPointerDown (UnityEngine.EventSystems.PointerEventData eventData)
    {
        CreateKeyboard ();
        base.OnPointerDown (eventData);
    }

    public override void OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData)
    {
        CreateKeyboard ();
        base.OnPointerClick (eventData);
    }
}
Gok
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away