示例#1
0
    internal static void ReplaceUnityInputField(InputField unityInputField)
    {
        if (unityInputField == null)
        {
            return;
        }

        Graphic    _targetGraphic  = unityInputField.targetGraphic;
        ColorBlock _colors         = unityInputField.colors;
        Color      _selectionColor = unityInputField.selectionColor;

        TMP_InputField.ContentType _contentType = (TMP_InputField.ContentType)unityInputField.contentType;
        TMP_InputField.LineType    _lineType    = (TMP_InputField.LineType)unityInputField.lineType;
        int _characterLimit = unityInputField.characterLimit;


        GameObject obj = unityInputField.gameObject;

        Undo.DestroyObjectImmediate(unityInputField);

        TMP_InputField tmproInputField = Undo.AddComponent <TMP_InputField>(obj);

        tmproInputField.targetGraphic  = _targetGraphic;
        tmproInputField.colors         = _colors;
        tmproInputField.selectionColor = _selectionColor;
        tmproInputField.contentType    = _contentType;
        tmproInputField.lineType       = _lineType;
        tmproInputField.characterLimit = _characterLimit;

        tmproInputField.targetGraphic.GetComponent <Image>();
    }
示例#2
0
        private InputFieldSetting CreateInputField(Transform parent, string name, TMP_InputField.ContentType contentType)
        {
            GameObject        inputFieldObject  = Instantiate(_inputSettingPrefab, parent);
            InputFieldSetting inputFieldSetting = inputFieldObject.GetComponent <InputFieldSetting>();

            inputFieldSetting.Name.text         = name;
            inputFieldSetting.Input.contentType = contentType;
            return(inputFieldSetting);
        }
        private void TMPInputFromInput(InputHandler handler)
        {
            if (handler == null)
            {
                return;
            }

            InputField input = handler.GetComponent <InputField>();

            if (input == null)
            {
                return;
            }

            int limit = input.characterLimit;

            TMP_InputField.ContentType content = GetTMPContentType(input.contentType);
            TMP_InputField.LineType    line    = TMPProUtil.LineType(input.lineType);
            float      caretBlinkRate          = input.caretBlinkRate;
            int        caretWidth     = input.caretWidth;
            Color      selectionColor = input.selectionColor;
            GameObject obj            = input.gameObject;

            RectTransform viewport      = handler.GetComponentInChildren <RectMask2D>().rectTransform;
            CWTextMeshPro placholder    = handler.GetComponentsInChildren <CWTextMeshPro>()[0];
            CWTextMeshPro textComponent = handler.GetComponentsInChildren <CWTextMeshPro>()[1];

            if (viewport == null || placholder == null || textComponent == null)
            {
                return;
            }

            MonoBehaviour.DestroyImmediate(input);

            CWTextMeshProInput tmp = obj.AddComponent <CWTextMeshProInput>();

            tmp.textViewport  = viewport;
            tmp.placeholder   = placholder;
            tmp.textComponent = textComponent;

            tmp.characterLimit = limit;
            tmp.contentType    = content;
            tmp.lineType       = line;
            tmp.caretBlinkRate = caretBlinkRate;
            tmp.caretWidth     = caretWidth;
            tmp.selectionColor = selectionColor;

            tmp.readOnly = false;
            tmp.shouldHideMobileInput = false;

            tmp.fontAsset = UISkinManager.TMPFont;
        }
示例#4
0
    public async Task <string> ShowInputAsync(string title, string description, TMP_InputField.ContentType contentType = TMP_InputField.ContentType.Standard)
    {
        var response = "";

        okInputCallback = s =>
        {
            response = s;
        };
        inputTitle.text        = I18n.T(title);
        inputBody.text         = I18n.T(description);
        inputField.text        = "";
        inputField.contentType = contentType;
        fsm.ChangeState(states.showInput);
        await TaskExtensions.WaitUntil(() => fsm.currentState != states.showInput);

        return(response);
    }
示例#5
0
 public UIInputField ContentType(TMP_InputField.ContentType type)
 {
     inputField.contentType = type;
     return(this);
 }
        public static DialogGUITextInput GUITextInput(String txt, Boolean multiline, Int32 maxlength,
                                                      Func <String, String> textSetFunc, Func <String> getString, TMP_InputField.ContentType contentType,
                                                      Single hght = -1f, Modifier <DialogGUITextInput> modifier = null)
        {
            DialogGUITextInput element =
                new DialogGUITextInput(txt, multiline, maxlength, textSetFunc, getString, contentType, hght);

            if (modifier != null)
            {
                element = modifier(element);
            }
            element.OnUpdate += () =>
            {
                if (element.uiItem == null)
                {
                    return;
                }
                if (element.uiItem.GetComponent <FixScrollRect>() != null)
                {
                    return;
                }
                element.uiItem.AddComponent <FixScrollRect>().MainScroll =
                    Part.GetComponentUpwards <ScrollRect>(element.uiItem);
            };
            _elements.Add(element);
            return(element);
        }
示例#7
0
 public void ShowInput(string title, string description, Action <string> okInputCallback, TMP_InputField.ContentType contentType = TMP_InputField.ContentType.Standard)
 {
     this.okInputCallback   = okInputCallback;
     inputTitle.text        = I18n.T(title);
     inputBody.text         = I18n.T(description);
     inputField.text        = "";
     inputField.contentType = contentType;
     fsm.ChangeState(states.showInput);
 }
        private TMP_InputField UpgradeInputField(InputField inputField)
        {
            if (!inputField)
            {
                return(null);
            }

            GameObject go = inputField.gameObject;

            stringBuilder.AppendLine("Upgrading InputField: " + GetPathOfObject(go.transform));

            // Copy fields
            Vector2 sizeDelta = ((RectTransform)inputField.transform).sizeDelta;
            SelectableObjectProperties selectableProperties = new SelectableObjectProperties(inputField);

            char  asteriskChar     = inputField.asteriskChar;
            float caretBlinkRate   = inputField.caretBlinkRate;
            bool  customCaretColor = inputField.customCaretColor;
            Color?caretColor       = null;

            try { caretColor = inputField.caretColor; } catch { }
            float caretWidth     = inputField.caretWidth;
            int   characterLimit = inputField.characterLimit;

            TMP_InputField.CharacterValidation characterValidation = GetTMPCharacterValidation(inputField.characterValidation);
            TMP_InputField.ContentType         contentType         = GetTMPContentType(inputField.contentType);
            bool enabled = inputField.enabled;

            TMP_InputField.InputType inputType    = GetTMPInputType(inputField.inputType);
            TouchScreenKeyboardType  keyboardType = inputField.keyboardType;

            TMP_InputField.LineType lineType = GetTMPLineType(inputField.lineType);
            bool   readOnly              = inputField.readOnly;
            Color  selectionColor        = inputField.selectionColor;
            bool   shouldHideMobileInput = inputField.shouldHideMobileInput;
            string _text = inputField.text;

            // Copy UnityEvents
            object onEndEdit = CopyUnityEvent(inputField.onEndEdit);

#if UNITY_5_3_OR_NEWER
            object onValueChanged = CopyUnityEvent(inputField.onValueChanged);
#else
            object onValueChanged = CopyUnityEvent(inputField.onValueChange);
#endif

            // Upgrade&copy child objects
            TextMeshProUGUI textComponent        = UpgradeText(inputField.textComponent);
            Graphic         placeholderComponent = (inputField.placeholder as Text) ? UpgradeText((Text)inputField.placeholder) : inputField.placeholder;

            // Replace InputField with TMP_InputField
            DestroyImmediate(inputField, true);
            TMP_InputField tmp = go.AddComponent <TMP_InputField>();

            // Paste child objects
            tmp.textComponent = textComponent;
            tmp.placeholder   = placeholderComponent;

            // Paste fields
            selectableProperties.ApplyTo(tmp);

            tmp.asteriskChar     = asteriskChar;
            tmp.caretBlinkRate   = caretBlinkRate;
            tmp.customCaretColor = customCaretColor;
            try { if (caretColor.HasValue)
                  {
                      tmp.caretColor = caretColor.Value;
                  }
            } catch { }
            tmp.caretWidth          = Mathf.RoundToInt(caretWidth);
            tmp.characterLimit      = characterLimit;
            tmp.characterValidation = characterValidation;
            tmp.contentType         = contentType;
            tmp.enabled             = enabled;
            tmp.inputType           = inputType;
            tmp.keyboardType        = keyboardType;
            if (tmp.lineType == lineType)
            {
                tmp.lineType = (TMP_InputField.LineType)(((int)lineType + 1) % 3);                                              // lineType adjusts Text's overflow settings but only if the lineType value is different
            }
            tmp.lineType = lineType;
            if (textComponent)
            {
                textComponent.overflowMode = TextOverflowModes.Overflow;                             // lineType doesn't modify this value, though. If must be set to Overflow for TMP_InputField texts
            }
            tmp.readOnly              = readOnly;
            tmp.selectionColor        = selectionColor;
            tmp.shouldHideMobileInput = shouldHideMobileInput;
            tmp.text = _text;

            ((RectTransform)tmp.transform).sizeDelta = sizeDelta;

            // Paste UnityEvents
            PasteUnityEvent(tmp.onEndEdit, onEndEdit);
            PasteUnityEvent(tmp.onValueChanged, onValueChanged);

            // TMP InputField objects have an extra Viewport (Text Area) child object, create it if necessary
            if (textComponent)
            {
                RectTransform viewport;
                if (textComponent.transform.parent != tmp.transform)
                {
                    viewport = (RectTransform)textComponent.transform.parent;
                }
                else
                {
                    viewport = CreateInputFieldViewport(tmp, textComponent, placeholderComponent);
                }

                if (!viewport.GetComponent <RectMask2D>())
                {
                    viewport.gameObject.AddComponent <RectMask2D>();
                }

                tmp.textViewport = viewport;
            }

            return(tmp);
        }