ユーザ用ツール

サイト用ツール

wiki:unity:tips:300

差分

この文書の現在のバージョンと選択したバージョンの差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
wiki:unity:tips:300 [2015/04/16 23:06]
step
wiki:unity:tips:300 [2015/12/16 12:07] (現在)
step
ライン 3: ライン 3:
 TouchScreenKeyboardクラスを使えばOSがサポートしているソフトウェアキーボードを使うことが出来ます。 TouchScreenKeyboardクラスを使えばOSがサポートしているソフトウェアキーボードを使うことが出来ます。
  
-<html+<code csharp
-<script src="https://gist.github.com/step5748/898703a1584921ac9bba.js"></script+// 処理サンプル 
-</html>+class Program 
 +
 +    // 状態。 
 +    enum E_STEP 
 +    { 
 +        WAIT, 
 +        INPUT_START,​ 
 +        INPUT_WAIT,​ 
 +    }; 
 +    private E_STEP m_eStep ​E_STEP.WAIT;​ 
 + 
 +    void SoftwareKeyboardAction() 
 +    { 
 +        switch (m_eStep) 
 +        { 
 +            case E_STEP.WAIT:​ 
 +                break; 
 + 
 +            case E_STEP.INPUT_START:​ 
 +                SoftwareKeyboard.Start("default string"​);​ 
 +                m_eStep = E_STEP.INPUT_WAIT;​ 
 +                break; 
 + 
 +            case E_STEP.INPUT_WAIT: 
 +                ​// ソフトウェアキーボード終了待ち。 
 +                if (!SoftwareKeyboard.IsEnd()) 
 +                { 
 +                    return; 
 +                } 
 + 
 +                ​// 結果受け取り。 
 +                switch (SoftwareKeyboard.GetResult()) 
 +                { 
 +                    case SoftwareKeyboard.E_RESULT.DONE:​ 
 +                        Debug.Log("DONE !!!! TEXT = " + SoftwareKeyboard.GetText());​ 
 +                        break; 
 + 
 +                    case SoftwareKeyboard.E_RESULT.CANCEL:​ 
 +                        Debug.Log("​CANCEL !!!! TEXT = " + SoftwareKeyboard.GetText());​ 
 +                        break; 
 +                } 
 +                m_eStep = E_STEP.WAIT;​ 
 +                break; 
 +        }; 
 +    } 
 +
 +</code> 
 + 
 +<code csharp>​ 
 +// SoftwareKeyboard.cs 
 +using UnityEngine;​ 
 + 
 +public class SoftwareKeyboard 
 +
 +    // 入力結果。 
 +    public enum E_RESULT 
 +    { 
 +        NONE = -1, 
 +        DONE,       //​!<​ 入力処理が終了した。 
 +        CANCEL, ​    //​!<​ 入力処理がキャンセルされた。 
 +    }; 
 + 
 +    private static TouchScreenKeyboard m_touchScreenKeyboard = null; 
 + 
 +    //​------------------------------------------------------------- 
 +    //! ソフトウェアキーボードオープン. 
 +    //​------------------------------------------------------------- 
 +    public static void Start(string _initString,​ TouchScreenKeyboardType _type = TouchScreenKeyboardType.Default) 
 +    { 
 +        // ソフトウェアキーボードをサポートしているか? 
 +        if (!TouchScreenKeyboard.isSupported) 
 +        { 
 +            // サポートしていない。 
 +            return; 
 +        } 
 + 
 +        // 既に表示されているか? 
 +        if (TouchScreenKeyboard.visible) 
 +        { 
 +        Debug.Log(false,​ "​Software keyboard already exists."​);​ 
 +            return; 
 +        } 
 + 
 +        // ソフトウェアキーボードオープン 
 +        m_touchScreenKeyboard = TouchScreenKeyboard.Open(_initString,​ _type); 
 +    } 
 + 
 +    //​------------------------------------------------------------- 
 +    //! ソフトウェアキーボード終了確認. 
 +    //​------------------------------------------------------------- 
 +    public static bool IsEnd() 
 +    { 
 +        if (m_touchScreenKeyboard == null) 
 +        { 
 +            return true; 
 +        }; 
 + 
 +        if (m_touchScreenKeyboard.done || m_touchScreenKeyboard.wasCanceled) 
 +        { 
 +            return true; 
 +        } 
 +        return false; 
 +    } 
 + 
 +    //​------------------------------------------------------------- 
 +    //! 入力結果を返す. 
 +    //​------------------------------------------------------------- 
 +    public static E_RESULT GetResult() 
 +    { 
 +        if (m_touchScreenKeyboard == null) 
 +        { 
 +            return E_RESULT.NONE;​ 
 +        }; 
 + 
 +        // 入力の処理が終了したか 
 +        if (m_touchScreenKeyboard.done) 
 +        { 
 +            Debug.Log("​SoftwareKeyboard Done."​);​ 
 +            return E_RESULT.DONE;​ 
 +        } 
 +        // 入力処理がキャンセルされたかどうか 
 +        else if (m_touchScreenKeyboard.wasCanceled) 
 +        { 
 +            Debug.Log("​SoftwareKeyboard wasCanceled."​);​ 
 +            return E_RESULT.CANCEL;​ 
 +        } 
 +        else 
 +        { 
 +            Debug.Assert(false,​ "​Software keyboard invalid status."​);​ 
 +        } 
 +        return E_RESULT.NONE;​ 
 +    } 
 + 
 +    //​------------------------------------------------------------- 
 +    //! 入力文字列を返す. 
 +    //​------------------------------------------------------------- 
 +    public static string GetText() 
 +    { 
 +        if (m_touchScreenKeyboard == null) 
 +        { 
 +            return string.Empty;​ 
 +        }; 
 +        return m_touchScreenKeyboard.text;​ 
 +    } 
 +
 +</code> 
  
Permalink wiki/unity/tips/300.1429225587.txt.gz · 最終更新: 2015/04/16 23:06 by step

oeffentlich