123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #if (UNITY_ANDROID)
- #if HZMFUI
- using CommonUI.UI;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- namespace CommonUI_Unity3D_Android
- {
- public class UnityPlatformAndroidTextInput :MonoBehaviour
- {
- private UITextInput mInput = null;
- private int mMaxLength = 100;
- private string mText = "";
- protected TouchScreenKeyboard mKeyboard;
- public void SetInput(UITextInput input)
- {
-
- if(input == null && mInput != null && !mInput.IsDispose)
- {
- mInput.FadeTextField(false);
- mInput.Text = mText;
- mInput.SetInputFinish(mText);
- if(mKeyboard != null)
- {
- mKeyboard.active = false;
- }
- }
- mInput = input;
-
- if(mInput != null && !mInput.IsDispose)
- {
- mInput.FadeTextField(true);
- mMaxLength = input.MaxLength;
- mText = mInput.Text;
- mKeyboard = TouchScreenKeyboard.Open(mText, ConvertKeyBoardType(mInput.InputType), false);
- }
- }
- void Update()
- {
- if(mKeyboard != null)
- {
-
- string text = mKeyboard.text;
- if(text == null)
- {
- text = "";
- }
- if(mText != text && mInput != null && !mInput.IsDispose)
- {
- mText = "";
- for(int i = 0; i < text.Length; ++i)
- {
- char ch = text[i];
- ch = mInput.DoValidator(mText, ch);
- if(ch != 0)
- mText += ch;
- }
- if(mMaxLength > 0 && mText.Length > mMaxLength)
- mText = mText.Substring(0, mMaxLength);
- if(mText != text)
- mKeyboard.text = mText;
- UpdateInputText();
- }
-
- if(mKeyboard.done || !mKeyboard.active)
- {
- mKeyboard = null;
- this.SetInput(null);
- }
- }
- }
- private TouchScreenKeyboardType ConvertKeyBoardType(UITextInput.KeyBoardType type)
- {
- TouchScreenKeyboardType rlt = TouchScreenKeyboardType.Default;
- switch(type)
- {
- case UITextInput.KeyBoardType.NumberPad:
- rlt = TouchScreenKeyboardType.NumberPad;
- break;
- case UITextInput.KeyBoardType.PhonePad:
- rlt = TouchScreenKeyboardType.PhonePad;
- break;
- case UITextInput.KeyBoardType.EmailAddress:
- rlt = TouchScreenKeyboardType.EmailAddress;
- break;
- default:
- break;
- }
- return rlt;
- }
- private void UpdateInputText()
- {
- mInput.Text = mText;
- }
- }
- }
- #endif
- #endif
|