需求:unity内置的调节间距的只有行距,无法调节字的间距,只能通过代码来实现调节字间距的效果。
内容我是百度别人的拿来直接用的,附一下大佬的地址

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Playables;
using UnityEngine.SceneManagement;
using UnityEngine.UI;namespace ZXL
{/// <summary>/// 对话系统/// </summary>public class DialogueSystem : MonoBehaviour{public Sprite[] sprites;public Image img_HeadPortrait;public Text txt_Context;public string path;//文件路径List<string> imgList;List<string> txtList;private int index;public float logSpeed;//打印速度private bool isLoging;//打印中private bool isLog;//直接打印private void Awake(){imgList = new List<string>();txtList = new List<string>();index = 0;isLoging = false;isLog = true;path = Application.streamingAssetsPath + "/Load/" + path;//Analysis(path);//StartCoroutine(Send(path));isFirst = true;//sprites[0] = Resources.Load<Sprite>("/sprite/老板头像_03");//sprites[1] = Resources.Load<Sprite>("/sprite/小白头像_03");//sprites[2] = Resources.Load<Sprite>("/sprite/小精灵头像_03");}private void OnEnable(){//index = 0;//isLoging = false;//PlayDialogue(path);StartCoroutine(Send(path));}bool isFirst;//private void Update()//{//    //if (Input.GetKeyDown(KeyCode.Q))//    //{//    //    //if (!isLoging && !isLog)//    //    //    StartCoroutine(SS());//    //    //else if (!isLog && isLoging)//    //    //    isLog = !isLog;//    //    PlayDialogue();//    //}//    Debug.Log(isTrue);//}public void PlayDialogue(){//index = 0;//isLoging = false;//isLog = true;//this.path = path;StartCoroutine(SS());}/// <summary>/// 解析/// </summary>public void Analysis(string path){string[] s = File.ReadAllLines(path);for (int i = 0; i < s.Length; i++){if (i % 2 == 0) imgList.Add(s[i]);else txtList.Add(s[i]);}}private bool isTrue;IEnumerator Send(string url){UnityWebRequest request = UnityWebRequest.Get(url);yield return request.SendWebRequest();if (request.isHttpError || request.isNetworkError){UnityEngine.Debug.Log(request.error);}else{UnityEngine.Debug.Log(request.downloadHandler.text);string[] s = request.downloadHandler.text.Split('\n');string[] ss = new string[s.Length];for (int i = 0; i < ss.Length; i++){//Debug.Log(ss[i]);ss[i] = s[i].Replace("\r", "");}for (int i = 0; i < ss.Length; i++){if (i % 2 == 0) imgList.Add(ss[i]);else txtList.Add(ss[i]);}isTrue = true;}}public void BedRoomOnly(){StopAllCoroutines();OverallSituation.instance.audioManager.StopAudio();img_HeadPortrait.gameObject.SetActive(false);//OverallSituation.instance.audioManager.PlayAudio(num);//音频还未给,后面更改索引txt_Context.text = "";}IEnumerator SS(){yield return isTrue;//Debug.Log("imgList.Count" + imgList.Count + "+" + "index" + index);if (index >= imgList.Count){Debug.Log("退出");//OverallSituation.instance.mainCanvas.shiYanModelChooseButton.SetActive(true);yield break;}if (isFirst){OverallSituation.instance.audioManager.PlayAudio(num);isFirst = false;}//Debug.Log(index);isLoging = true;txt_Context.text = "";//char[] c = txtList[index].ToCharArray();switch (imgList[index]){case "老板":img_HeadPortrait.sprite = sprites[0];//img_HeadPortrait.color = Color.green;break;case "小白":img_HeadPortrait.sprite = sprites[1];//img_HeadPortrait.color = Color.red;break;case "精灵":img_HeadPortrait.sprite = sprites[2];//img_HeadPortrait.color = Color.blue;break;default:break;}//int i = 0;//while (!isLog && i < c.Length - 1)//{//    txt_Context.text += c[i];//    i++;//    yield return new WaitForSeconds(logSpeed);//}//if (isLog) txt_Context.text = txtList[index];Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();if (scene.name == "Company0"){if (index == 0)yield return new WaitForSeconds(1f);//1else if (index == 1)yield return new WaitForSeconds(3f);//4else if (index == 2)yield return new WaitForSeconds(2.5f);//6.5else if (index == 3)yield return new WaitForSeconds(2.5f);//9else if (index == 4)yield return new WaitForSeconds(4f);//13else if (index == 5)yield return new WaitForSeconds(1f);//12.20}else if (scene.name == "StudyAndBedRoom0"){if (index == 0)yield return new WaitForSeconds(2f);else if (index == 1)yield return new WaitForSeconds(2.5f);else if (index == 2)yield return new WaitForSeconds(3.5f);}else if (scene.name == "MengJingDaTing0"){if (index == 0)yield return new WaitForSeconds(2f);//2else if (index == 1)yield return new WaitForSeconds(2.5f);//4.5else if (index == 2)yield return new WaitForSeconds(1.5f);//6else if (index == 3)yield return new WaitForSeconds(3f);//9else if (index == 4)yield return new WaitForSeconds(5f);//14else if (index == 5)yield return new WaitForSeconds(1.5f);//15.5else if (index == 6)yield return new WaitForSeconds(5.5f);//21}else if (scene.name == "Company1"){if (index == 0)yield return new WaitForSeconds(1f);else if (index == 1)yield return new WaitForSeconds(2f);else if (index == 2)yield return new WaitForSeconds(1.5f);}isLog = false;isLoging = false;index++;OverallSituation.instance.mainCanvas.num_Dialog++;PlayDialogue();}public int num;}
}

直接挂载上去即可。
本文仅做个人记录使用,如有问题,请及时联系!

Unity笔记之调节text的字间距相关推荐

  1. ios label文字行间距_ios实践之Label 字间距、行间距、两端对齐、分行显示

    UILabel算是iOS里使用最多的控件了吧,下面来说说它特殊的应用需求吧 一.设置字间距.行间距 这是一个比较常见的需求了 写一个UILabel的分类 @interface UILabel (ext ...

  2. Unity Text字间距和行间距调整

    一.问题 在3D场景中常见文字,通过调整字体大小和锚点放大文字和清晰度,但是无法调整字间距,同时网上资料可以调整字间距,但是换行前面会出现空白. 二.解决办法 通过重新ModifyMesh函数到达调整 ...

  3. Unity 工具控件 之 Text 文本字间距调整(老版本的Unity编写工具控件/新版本Unity使用TMP)

    Unity 工具控件 之 Text 文本字间距调整(老版本的Unity编写工具控件/新版本Unity使用TMP) 目录 Unity 工具控件 之 Text 文本字间距调整(老版本的Unity编写工具控 ...

  4. html怎样调节字间距,css怎么调整字间距?

    css文字与文字之间的间距怎么调整?相信有很多小伙伴都会有这样的疑问.本章就给大家介绍css设置文字间距的方法.有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助. 一.css word- ...

  5. 2016/8/2 CSS学习笔记 css 字间距、CSS字体间距、css 字符间距

    1.text-indent设置抬头距离css缩进 即对,对应div设置css样式text-indent : 20px; 缩进了20px 2.letter-spacing来设置字与字间距_字符间距离,字 ...

  6. iOS UIlabel文字排版(改变字间距行间距)分类

    在iOS开发中经常会用到UIlabel来展示一些文字性的内容,但是默认的文字排版会觉得有些挤,为了更美观也更易于阅读我们可以通过某些方法将UIlabel的行间距和字间距按照需要调节. 比如一个Labe ...

  7. 真正解决TextView行间距、字间距的问题

    1.修改行间距(最简单) 在xml中设置 (1)lineSpacingMultiplier属性,意思是行与行之间的距离倍数,相当于word里面的行间距,例如1.5倍行间距 android:lineSp ...

  8. 字间距、词间距的使用-CSS入门基础(010)

    今天我们接着分享文本样式的内容. letter-spacing字母间距: 在css中,我们可以使用letter-spacing属性定义字间距. 语法: letter-spacing:像素值: 我们一般 ...

  9. Unity 关于Ugui之text组件的扩展

    在项目开发中,和ui界面打交道是必不可少的,但是最近发现ugui提供的text组件,在很多情况下不能满足美术的需求,这就对text组件进行扩展编辑,使其尽可能满足项目的需求,这里主要实现字间距.字体颜 ...

最新文章

  1. python 使用session_使用session和只使用session有什么区别
  2. 上海虹桥站 启动建设5G网络,DMA助力5G加速
  3. 一文了解OOM及解决方案
  4. EF中 GroupJoin 与 Join
  5. arduino pmw 串口 字符串_ESP32 Arduino开发:串口(Serial port)
  6. 【CodeForces - 1150A】Stock Arbitraging (贪心,水题)
  7. post python爬虫_小白学 Python 爬虫(17):Requests 基础使用
  8. js 正则或_Web前端工程师要知道的JS 常用正则表达式
  9. 从字节码层面,解析 Java 布尔型的实现原理
  10. Java垃圾回收机制分析
  11. 2018最新qq的服务器地址,腾讯QQ2018正式版新功能详细介绍
  12. 查找与清除线程插入式木马(转)
  13. SpringBoot 重置 kafka 偏移量offset(kafka-0.10.1.0)
  14. CVPR 2021 | 港科大:如何利用闪光图像(flash image)来去除反光?
  15. vue3 倒计时3秒后返回首页
  16. 使用视频作为网页背景的写法
  17. mysql db2 性能_确定DB2 Java应用程序的性能问题
  18. ES6(一)ES6的开发环境搭建(es6转码为es5)
  19. qq测试常用软件,测速软件有哪些_测速软件实用推荐
  20. 华为OBS对象存储,每个人都应该用一用

热门文章

  1. java宠物小精灵_4978:宠物小精灵之收服
  2. 15k的php会什么,【后端开辟】15k的php须要控制什么手艺
  3. pip安装的依赖不在虚拟环境中
  4. 所有的想不通,都是因为你不懂
  5. SQL service基础(二)对数据指定列查询、条件查询、查询结果排序、聚集函数查询、分组统计查询
  6. 腾讯进“鸡”加持智能网络,发布Supermind
  7. 60分钟搞定JAVA加解密
  8. Designing Data-Intensive Application《数据密集型应用系统设计》笔记
  9. 松软科技web课堂:SQLServer之UCASE() 函数
  10. 远程调用报错java.net.UnknownHostException 解决方法