Пример #1
0
        /// <summary>
        /// 插入字符串
        /// </summary>
        /// <param name="str">字符串</param>
        public void InsertString(string str)
        {
            var es = new EmojiString(str);

            TextOperation.DeleteSelectString();
            TextOperation.InsertContent(es);
        }
Пример #2
0
        public void InsertString(string str)
        {
            Style = 1;
            DeleteSelectString();
            var es = new EmojiString(str);
            int c  = es.Length;

            Text.Insert(StartIndex, es);
            GetPreferredHeight();
            StartIndex += c;
            pressOffset = StartPress.Offset;
            textChanged = true;
            lineChanged = true;
            SetShowStart();
        }
Пример #3
0
        string OnInputChanged(string input)
        {
            if (input == "")
            {
                return("");
            }
            EmojiString es  = new EmojiString(input);
            string      str = textInfo.buffer.FilterString;

            if (CharacterLimit > 0)
            {
                string fs = es.FilterString;
                if (fs.Length + str.Length > CharacterLimit)
                {
                    int len = CharacterLimit - str.Length;
                    if (len <= 0)
                    {
                        return("");
                    }
                    es.Remove(fs.Length - len, len);
                }
            }
            str = es.FullString;
            if (Validate(characterValidation, textInfo.text, textInfo.startSelect, str[0]) == 0)
            {
                return("");
            }
            if (ValidateChar != null)
            {
                if (ValidateChar(this, textInfo.startSelect, str[0]) == 0)
                {
                    return("");
                }
            }
            DeleteSelected(textInfo);
            textInfo.buffer.Insert(textInfo.startSelect, es);
            textInfo.startSelect += es.FilterString.Length;
            if (OnValueChanged != null)
            {
                OnValueChanged(this);
            }
            textInfo.text = textInfo.buffer.FullString;
            SetShowText();
            textInfo.CaretStyle = 1;
            selectChanged       = true;
            textChanged         = true;
            return(input);
        }
Пример #4
0
        string OnInputChanged(string input)
        {
            if (ReadOnly)
            {
                return("");
            }
            if (input == null | input == "")
            {
                return("");
            }
            EmojiString es  = new EmojiString(input);
            string      str = FullString.FilterString;

            if (CharacterLimit > 0)
            {
                string fs = es.FilterString;
                if (fs.Length + str.Length > CharacterLimit)
                {
                    int len = CharacterLimit - str.Length;
                    if (len <= 0)
                    {
                        return("");
                    }
                    es.Remove(len, fs.Length - len);
                }
            }
            str = es.FullString;
            int s = TextOperation.StartPress.Index;

            if (CharOperation.Validate(characterValidation, str, s, str[0]) == 0)
            {
                return("");
            }
            if (ValidateChar != null)
            {
                if (ValidateChar(this, s, str[0]) == 0)
                {
                    return("");
                }
            }
            InsertString(str);
            SetShowText();
            return(str);
        }
Пример #5
0
        string OnInputChanged(string input)
        {
            if (input == "")
            {
                return("");
            }
            EmojiString es  = new EmojiString(input);
            string      str = Text.FullString;

            if (CharacterLimit > 0)
            {
                string fs = es.FilterString;
                if (fs.Length + str.Length > CharacterLimit)
                {
                    int len = CharacterLimit - str.Length;
                    if (len <= 0)
                    {
                        return("");
                    }
                    es.Remove(fs.Length - len, len);
                }
            }
            str = es.FullString;
            int s = StartIndex;

            if (CharOperation.Validate(characterValidation, Text.FullString, s, str[0]) == 0)
            {
                return("");
            }
            if (ValidateChar != null)
            {
                if (ValidateChar(this, s, str[0]) == 0)
                {
                    return("");
                }
            }
            InsertString(str);
            return(input);
        }
        public static void AsyncGetSizeY(string fontName, Vector2 designSize, int fontSize, EmojiString txt, FontStyle style, Action <Vector2> callback)
        {
            string  str = txt.FilterString;
            Vector2 v   = Vector2.zero;

            ThreadMission.InvokeToMain((o) => {
                var font = FindFont(fontName);
                if (font != null)
                {
                    TextGenerationSettings settings = new TextGenerationSettings();
                    settings.resizeTextMinSize      = 2;
                    settings.resizeTextMaxSize      = 40;
                    settings.scaleFactor            = 1;
                    settings.textAnchor             = TextAnchor.UpperLeft;
                    settings.color             = Color.red;
                    settings.generationExtents = new Vector2(designSize.x, 0);
                    settings.pivot             = new Vector2(0.5f, 0.5f);
                    settings.richText          = true;
                    settings.font               = font;
                    settings.fontSize           = fontSize;
                    settings.fontStyle          = FontStyle.Normal;
                    settings.alignByGeometry    = false;
                    settings.updateBounds       = false;
                    settings.lineSpacing        = 1;
                    settings.horizontalOverflow = HorizontalWrapMode.Wrap;
                    settings.verticalOverflow   = VerticalWrapMode.Overflow;
                    TextGenerator generator     = new TextGenerator();
                    v.y = generator.GetPreferredHeight(str, settings);
                    v.x = designSize.x;
                    if (generator.lineCount == 1)
                    {
                        v.x = generator.verts[generator.vertexCount - 1].position.x - generator.verts[0].position.x + 0.1f;//加0.1增加容错率
                    }
                }
            },
                                       null,
                                       (o) => {
                if (callback != null)
                {
                    callback(v);
                }
            });
        }