Exemplo n.º 1
0
        private void Open_Private(string tText, string tTextPlaceholder, KeyboardType tKeyboardType, bool tIsMultiLine, bool tIsSecure, bool tHideInput, Action <State, string> tOnValueChaned)
        {
            // コールバックを登録する
            m_OnValueChanged = tOnValueChaned;

            // 初期の文字列を保存する
            m_InitialText = tText;

            // 現在の文字列を保存する
            m_ActiveText = tText;

            //-------------------------------------------------

#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS)
            // 実機
            TouchScreenKeyboardType tMobileKeyboardType = TouchScreenKeyboardType.Default;
            if (tKeyboardType == KeyboardType.Default)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.Default;
            }
            else
            if (tKeyboardType == KeyboardType.ASCIICapable)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.ASCIICapable;
            }
            else
            if (tKeyboardType == KeyboardType.NumbersAndPunctuation)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.NumbersAndPunctuation;
            }
            else
            if (tKeyboardType == KeyboardType.URL)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.URL;
            }
            else
            if (tKeyboardType == KeyboardType.NumberPad)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.NumberPad;
            }
            else
            if (tKeyboardType == KeyboardType.PhonePad)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.PhonePad;
            }
            else
            if (tKeyboardType == KeyboardType.NamePhonePad)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.NamePhonePad;
            }
            else
            if (tKeyboardType == KeyboardType.EmailAddress)
            {
                tMobileKeyboardType = TouchScreenKeyboardType.EmailAddress;
            }

            TouchScreenKeyboard.hideInput = tHideInput;

            m_VirtualKeyboard = TouchScreenKeyboard.Open
                                (
                tText,
                tMobileKeyboardType,
                true,
                tIsMultiLine,
                tIsSecure,
                false,
                tTextPlaceholder
                                );
#else
            // PC

            // フルスクリーンのキャンバスを生成する
            UICanvas tCanvas = UICanvas.CreateWithCamera(transform, 0, 0);


            // キャンバスのカメラを取得する
            Camera tCamera = tCanvas.GetCanvasCamera();

            // キャンバスのカメラをかなり手前に設定する
            tCamera.depth = 32767;

            // カメラを塗りつぶさないようにする
            tCamera.clearFlags = CameraClearFlags.Nothing;

            // 全画面用のイメージを追加する
            UIImage tScreen = tCanvas.AddView <UIImage>("Virtaul Keyboard Screen");
            tScreen.SetAnchorToStretch();               // 全画面表示にする
            tScreen.isMask = true;
            tScreen._mask.showMaskGraphic = false;

            Vector2 tCanvasSize = tScreen.GetCanvasSize();

            float cw = tCanvasSize.x;              // tCanvas._w ;
            float ch = tCanvasSize.y;              // tCanvas._h ;

            // 最も基本的な縦の長さ
            float bw = cw;
            float bh = ch * 0.1f;

            int tFontSize = ( int )(bh * 0.4f);

            //---------------------------------------------------------

            // 土台部分を作る
            UIImage tBase = tScreen.AddView <UIImage>("Base");
            tBase.SetAnchorToStretchBottom();
            tBase.SetPivotToCenterBottom();

            if (tIsMultiLine == false)
            {
                // シングル
                tBase._h = bh * 2;
            }
            else
            {
                // マルチ
                tBase._h = bh * 6;
            }

            // テキスト入力部を作る
            string tOption = "";
            if (tIsMultiLine == true)
            {
                tOption = "MultiLine";
            }
            UIInputField tInputField = tBase.AddView <UIInputField>("Input", tOption);
            tInputField.SetAnchorToStretchTop();
            tInputField.SetPivotToCenterTop();
            tInputField.SetMarginX(2, 2);
            tInputField._y = -2;

            tInputField.text             = tText;
            tInputField.placeholder.text = tTextPlaceholder;

            if (tIsMultiLine == false)
            {
                tInputField._h = (bh * 1) - 4;
            }
            else
            {
                tInputField._h = (bh * 5) - 4;

                // デフォルトでニューラインになっているのでサブミットに変える
                tInputField.lineType = UnityEngine.UI.InputFieldPlus.LineType.MultiLineSubmit;
            }
            tInputField.SetFontSize(tFontSize);

            if (tKeyboardType == KeyboardType.Default)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Standard;
            }
            else
            if (tKeyboardType == KeyboardType.ASCIICapable)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Alphanumeric;
            }
            else
            if (tKeyboardType == KeyboardType.NumbersAndPunctuation)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.IntegerNumber;
            }
            else
            if (tKeyboardType == KeyboardType.URL)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Autocorrected;
            }
            else
            if (tKeyboardType == KeyboardType.NumberPad)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.DecimalNumber;
            }
            else
            if (tKeyboardType == KeyboardType.PhonePad)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Pin;
            }
            else
            if (tKeyboardType == KeyboardType.NamePhonePad)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Name;
            }
            else
            if (tKeyboardType == KeyboardType.EmailAddress)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.EmailAddress;
            }

            if (tIsSecure == true)
            {
                tInputField.contentType = UnityEngine.UI.InputFieldPlus.ContentType.Password;
            }

            // 状態が変化した際に呼び出される
            tInputField.SetOnValueChanged(OnValueChanged);

            // リターンキーによる決定時に呼び出される
            //	tInputField.SetOnEndEditDelegate( OnEndEdit ) ;
            tInputField.SetOnEnterKeyPressed(OnEndEdit);


            // OKボタンを作る
            UIButton tButton_OK = tBase.AddView <UIButton>("OK");
            tButton_OK.SetAnchorToLeftBottom();
            tButton_OK.SetSize(bw * 0.5f - 4, bh - 4);
            tButton_OK.SetPosition(bw * 0.25f, bh * 0.5f);
            tButton_OK.AddLabel("OK", 0xFFFFFFFF, tFontSize);
            tButton_OK.SetOnButtonClick(OnClick);

            // CANCELボタンを作る
            UIButton tButton_Cancel = tBase.AddView <UIButton>("Cancel");
            tButton_Cancel.SetAnchorToRightBottom();
            tButton_Cancel.SetSize(bw * 0.5f - 4, bh - 4);
            tButton_Cancel.SetPosition(-bw * 0.25f, bh * 0.5f);
            tButton_Cancel.AddLabel("CANCEL", 0xFFFFFFFF, tFontSize);
            tButton_Cancel.SetOnButtonClick(OnClick);

            float tH = tBase._h;

            UITween tTweenUp = tBase.AddTween("Up");
            tTweenUp.delay            = 0;
            tTweenUp.duration         = 0.25f;
            tTweenUp.positionEnabled  = true;
            tTweenUp.positionEaseType = UITween.EaseType.easeOutQuad;
            tTweenUp.positionFromY    = -tH;
            tTweenUp.playOnAwake      = false;

            UITween tTweenDown = tBase.AddTween("Down");
            tTweenDown.delay            = 0;
            tTweenDown.duration         = 0.25f;
            tTweenDown.positionEnabled  = true;
            tTweenDown.positionEaseType = UITween.EaseType.easeOutQuad;
            tTweenDown.positionToY      = -tH;
            tTweenDown.playOnAwake      = false;

            tTweenDown.SetOnFinished((string tIdentity, UITween tTween) =>
            {
                Destroy(gameObject);
            });

            tBase.PlayTween("Up");

            m_Base = tBase;
#endif
        }