zoukankan      html  css  js  c++  java
  • unity 如何在text中的单词过长时 避免自动添加空格并换行

    在unity中,text里如果单词过长会自动往此行末尾留空并换行。

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class WenBenHuanHang : MonoBehaviour {
        [SerializeField]
        Text mText;
        private bool m_IsSpace=true;
    
        // Use this for initialization
        void Start () {
            settext();
    
        }
        
        // Update is called once per frame
        void Update () {
            
        }
        private void settext()
        {
            //获取Text的文本内容
            string temp_content = mText.text;
            string temp_indent = "";
            //首行缩进的字符数
            int m_Text_indent = 2;
            for (int i = 0; i < m_Text_indent; i++)
            {
                temp_indent = string.Format("{0}{1}", temp_indent, "u3000");
            }
            temp_content = string.Format("{0}{1}", temp_indent, mText.text);
            //处理空格
            if (m_IsSpace)
            {
                temp_content = temp_content.Replace(" ", "u3000");
            }
            //首行缩进替换
            temp_content = temp_content.Replace("
    ", "
    " + temp_indent);
            //重新设置Text文字
            mText.text = temp_content;
        }
    }

    使用上述脚本后

  • 相关阅读:
    linux运维、架构之路-MySQL主从复制
    多线程
    IO
    查看信息
    乱码
    字节流与字符流
    file
    JDBC
    规范
    Java常用包
  • 原文地址:https://www.cnblogs.com/lingLuoChengMi/p/12488296.html
Copyright © 2011-2022 走看看