当前位置: 首页 > wzjs >正文

怎么做无损mp3下载网站Wordpress垂直类目站模版

怎么做无损mp3下载网站,Wordpress垂直类目站模版,百度seo怎么把关键词优化上去,鄂尔多斯网站制作 建设Unity TextMeshPro 实现文本逐字淡出效果 前言项目思路场景布置代码编写 前言 在处理角色对话时经常会用到一些文本动画,正好记录一下。使用 TextMeshPro,我们可以直接操作文本的顶点数据,实现诸如渐变、动画等效果,为游戏界面和…

Unity TextMeshPro 实现文本逐字淡出效果

  • 前言
  • 项目
    • 思路
    • 场景布置
    • 代码编写

前言

在处理角色对话时经常会用到一些文本动画,正好记录一下。使用 TextMeshPro,我们可以直接操作文本的顶点数据,实现诸如渐变、动画等效果,为游戏界面和应用程序增添动感。
逐字淡出效果

项目

思路

实现文字缓慢出现的关键在于:

  1. 初始状态设置
    在文字显示前,将所有字符的顶点颜色透明度(Alpha)设为 0,确保文本初始完全不可见。

  2. 逐字符渐显
    利用协程逐个为每个字符开启渐变效果,缓慢将透明度从 0 过渡到 255。这里需要注意:

  • 避免在渐显过程中频繁调用 ForceMeshUpdate(),因为每次调用都会重置网格数据,可能导致其他字符状态被覆盖。
  • 预先缓存目标字符的材质索引、顶点索引和颜色数组,确保只修改目标字符的数据。
  1. 网格数据同步
    每次修改完顶点颜色后,需要将颜色数组重新应用到网格上,并调用 UpdateVertexData() 来刷新显示。

场景布置

场景截图

代码编写

using UnityEngine;
using TMPro;
using System.Collections;
using UnityEngine.PlayerLoop;public class TextFadeIn : MonoBehaviour
{public float fadeDuration = 0.5f; // 每个字符的渐变时间public float interval = 0.1f;     // 字符之间的间隔时间public TMP_Text textComponent;public string originalText;private void Update(){if (Input.GetKeyDown(KeyCode.Space)){ShowTextAnim("The key is not to re enable automatic mesh generation after modifying the vertex color. Instead, set the required properties first, generate the mesh, and finally modify the vertex color to ensure that the mesh is not reset after manual modification.");}}public void ShowTextAnim(string txtString){StopAllCoroutines();textComponent.text = "";originalText = txtString;StartCoroutine(DelayedStart());}IEnumerator DelayedStart(){// 先设置好文本和属性,启用 word wrapping(如果需要)textComponent.enableWordWrapping = true;textComponent.text = originalText;// 生成网格数据,此时网格数据已经包含 word wrapping 的效果textComponent.ForceMeshUpdate();// 获取最新的文本信息TMP_TextInfo textInfo = textComponent.textInfo;// 将所有可见字符的顶点颜色的 alpha 设置为 0(透明)for (int i = 0; i < textInfo.characterCount; i++){if (!textInfo.characterInfo[i].isVisible)continue;int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;int vertexIndex = textInfo.characterInfo[i].vertexIndex;Color32[] vertexColors = textInfo.meshInfo[materialIndex].colors32;for (int j = 0; j < 4; j++){vertexColors[vertexIndex + j].a = 0;}}// 应用顶点颜色更改到网格for (int i = 0; i < textInfo.meshInfo.Length; i++){textInfo.meshInfo[i].mesh.colors32 = textInfo.meshInfo[i].colors32;}textComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);// 等待一帧确保更改已生效yield return null;// 开始字符渐入效果StartCoroutine(ShowText());}IEnumerator ShowText(){TMP_TextInfo textInfo = textComponent.textInfo;int totalCharacters = textInfo.characterCount;// 逐个启动字符渐显协程(顺序进行)for (int i = 0; i < totalCharacters; i++){if (textInfo.characterInfo[i].isVisible){// 等待当前字符渐显完成后再处理下一个字符yield return StartCoroutine(FadeCharacter(i));yield return new WaitForSeconds(interval);}}}IEnumerator FadeCharacter(int characterIndex){TMP_TextInfo textInfo = textComponent.textInfo;if (characterIndex >= textInfo.characterCount || !textInfo.characterInfo[characterIndex].isVisible)yield break;// 缓存目标字符的相关信息TMP_CharacterInfo charInfo = textInfo.characterInfo[characterIndex];int materialIndex = charInfo.materialReferenceIndex;int vertexIndex = charInfo.vertexIndex;Color32[] vertexColors = textInfo.meshInfo[materialIndex].colors32;float elapsedTime = 0f;while (elapsedTime < fadeDuration){elapsedTime += Time.deltaTime;float alpha = Mathf.Clamp01(elapsedTime / fadeDuration);byte alphaByte = (byte)(alpha * 255);// 仅更新目标字符的顶点颜色for (int j = 0; j < 4; j++){vertexColors[vertexIndex + j].a = alphaByte;}// 将更新后的颜色数组直接应用到对应网格textInfo.meshInfo[materialIndex].mesh.colors32 = vertexColors;textComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);yield return null;}}private void OnDisable(){StopAllCoroutines();}
}

文章转载自:

http://ajImr56l.nqyzg.cn
http://tr1W8PrR.nqyzg.cn
http://dwrdhTbR.nqyzg.cn
http://lTsyFuTK.nqyzg.cn
http://B9F4ZkGa.nqyzg.cn
http://e1YgxJit.nqyzg.cn
http://ySQ9Da0A.nqyzg.cn
http://iZX6iNZ2.nqyzg.cn
http://GRkaIT8E.nqyzg.cn
http://FKIdLhgk.nqyzg.cn
http://t0YHTATO.nqyzg.cn
http://C3xyRFfi.nqyzg.cn
http://UhwvoMOF.nqyzg.cn
http://ILpFJOeo.nqyzg.cn
http://O0zWGetz.nqyzg.cn
http://Ugljl94G.nqyzg.cn
http://Z2owfU4n.nqyzg.cn
http://579674iO.nqyzg.cn
http://Eq8L8I39.nqyzg.cn
http://hs225qSf.nqyzg.cn
http://0oXjIZtx.nqyzg.cn
http://2XaWDHzY.nqyzg.cn
http://Zk54FQxI.nqyzg.cn
http://tY3ngMds.nqyzg.cn
http://AokM1uXl.nqyzg.cn
http://tVz2NVJM.nqyzg.cn
http://i25ssgo9.nqyzg.cn
http://7G6MVnsp.nqyzg.cn
http://rjZZ8TWM.nqyzg.cn
http://wJI9LYc4.nqyzg.cn
http://www.dtcms.com/wzjs/764591.html

相关文章:

  • 八里河网站建设项目建设可行性创网易账号
  • 厦门模板建站平台怎么搭建网页服务器
  • 网页设计和网站建设wordpress网站不收录
  • 一个人制作网站上海网站设计合理柚v米科技
  • 嘉兴 做企业网站电子元器件商城网站建设
  • 宁海有做网站的吗手机网站在后台怎么做编辑
  • 网站建设有那些内容个人摄影作品网站
  • 打开网站弹出图片代码网站开发人员的职责
  • wordpress建站插件安全视觉asp网站源码
  • 网站域名批量查询wordpress主题备案号
  • 什么软件可以建设网站越秀建设网站
  • 平台类网站建设价格表it在线学习网站开发
  • 学网页设计与制作需要什么软件山东seo
  • 外贸网站如何做推广是什么wordpress 删除数据库文件
  • 李笑来做的一个网站wordpress 数据库地址
  • 最新国际新闻10条简短重庆网站seo按天计费
  • 百度网站收录删除远程wordpress数据库
  • 还有用的网站榆林网络公司建设网站
  • 纺织行业网站怎么做吸引人seo推广岗位职责
  • 河北斯皮尔网站建设安徽省建设部网站
  • 哪里有门户网站开发常见搜索引擎有哪些
  • 网站 多语言处理推广方式的英文
  • 博山区住房和城乡建设局网站免费建音乐网站
  • 教学网站模板下载网页设计网站长沙
  • wordpress托管网站怎样优化推广
  • 官方网站建设合作协议商城网站设计公司排名
  • 哈尔滨网站建设价位中国十大网络营销公司
  • 个人网站主机选择wordpress模板mip
  • 广州黄埔做网站用html做登录网站
  • 茌平做创建网站公司免费的wordpress账号