Пример #1
0
    public void SetChineseFirstEnteredText()
    {
        string textStr = GetFirstChineseWord();

        textStr = string.IsNullOrEmpty(textStr) ? string.Empty : textStr;
        Text  chineseAlreadyInput = enteredRect.GetComponentInChildren <Text>();
        float sizeY = enteredRect.sizeDelta.y;
        float sizeX = KeyboardUtils.CaculateTextLength(textStr, enteredRect.GetComponentInChildren <Text>());

        enteredRect.sizeDelta = new Vector2(sizeX + 160, sizeY);
        LayoutRebuilder.ForceRebuildLayoutImmediate(enteredRect);
        chineseAlreadyInput.text = textStr;
    }
Пример #2
0
    public void SetChineseWord(string chineseWord, int index)
    {
        this.chineseWord = chineseWord;
        Text          itemText = this.GetComponentInChildren <Text>();
        RectTransform itemRect = this.GetComponent <RectTransform>();
        float         sizeY    = itemRect.sizeDelta.y;

        if (string.IsNullOrEmpty(chineseWord))
        {
            itemText.text = "";
            SetRectSize(itemRect, 0, sizeY);
            return;
        }

        string displayWord = string.Format("{0}.{1}", (index + 1).ToString(), chineseWord);
        int    wordLength  = KeyboardUtils.CaculateTextLength(displayWord + 20, itemText);

        itemText.text = displayWord;
        SetRectSize(itemRect, wordLength, sizeY);

        this.onClick.RemoveAllListeners();
        this.onClick.AddListener(OnPromptItemClick);
    }