Tz2/Assets/InputFieldToContent.cs

25 lines
625 B
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class InputFieldToContent : MonoBehaviour
{
private static readonly string no_breaking_space = "\u00A0";
TMP_InputField m_InputField;
public TMP_Text m_Text;
void Start()
{
m_InputField = GetComponent<TMP_InputField>();
m_InputField.onValueChanged.AddListener((value) =>
{
//替换空格编码格式
m_InputField.text = m_InputField.text.Replace(" ", no_breaking_space);
m_Text.text = m_InputField.text;
});
}
}