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

unity 让文字变形

效果:

using TMPro;
using UnityEngine;
using NaughtyAttributes;[ExecuteInEditMode]
public class TMTextPerpective : MonoBehaviour
{[OnValueChanged("DoPerspective")][Range(-1f, 1f)]public float CenterBias = 0f;[OnValueChanged("DoPerspective")][Range(0f, 100f)]public float PValue = 0f;TMP_Text m_Text;void Awake(){m_Text = GetComponent<TMP_Text>();TMPro_EventManager.TEXT_CHANGED_EVENT.Add(OnTextMeshChanged);}void Start(){DoPerspective();}// Update is called once per framevoid Update(){}void OnTextMeshChanged(Object o){if (!Application.isPlaying)return;if (o == m_Text){ChangeText2Perspective();}}void ChangeText2Perspective(){//Debug.Log("-----------------ChangeText2Perspective--------------");TMP_TextInfo textInfo = m_Text.textInfo;int characterCount = textInfo.characterCount;if (characterCount == 0) return;float x_min = m_Text.bounds.min.x;float x_max = m_Text.bounds.max.x;float y_min = m_Text.bounds.min.y;float y_max = m_Text.bounds.max.y;float center_x = x_min + (x_max - x_min) * ((CenterBias + 1f) / 2f);//Debug.Log($"x center {center_x}");Vector3[] vertices;float aff_ratio = PValue / 100f;for (int i = 0; i < characterCount; i++){if (!textInfo.characterInfo[i].isVisible)continue;int vertexIndex = textInfo.characterInfo[i].vertexIndex;// Get the index of the mesh used by this character.int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;vertices = textInfo.meshInfo[materialIndex].vertices;for (int j = 0; j < 4; j++){Vector3 p = vertices[vertexIndex + j];float iratio = (p.y - y_min) / (y_max - y_min);//Debug.Log($"{textInfo.characterInfo[i].character} v {j} move percent {iratio} aff {aff_ratio}");p.x = p.x + (center_x - p.x) * aff_ratio * iratio;vertices[vertexIndex + j] = p;}}m_Text.UpdateVertexData();}[Button("执行")]void DoPerspective(){m_Text.ForceMeshUpdate();if (!Application.isPlaying)ChangeText2Perspective();}
}

http://www.lryc.cn/news/501598.html

相关文章:

  • Linux高并发服务器开发 第一天(Linux的目录结构 cd用法 终端提示符格式)
  • 可造成敏感信息泄露!Spring Boot之Actuator信息泄露漏洞三种利用方式总结
  • 支持图像和视频理解多模态开源大模型:CogVLM2 CogVLM2-Video
  • ClouderaManager 集群搭建
  • Docker 搭建 gitlab 服务器卡顿问题解决方法(创建:swap分区)
  • PVE修改IP地址
  • 智能合约的离线签名(EIP712协议)解决方案
  • 大模型Qwen面试内容整理-应用场景与案例分析
  • spring boot的统一异常处理,使用@RestControllerAdvice
  • OFCA-OpenHarmony课后习题答案
  • Open AI 推出 ChatGPT Pro
  • 利用PHP和GD库实现图片切割
  • 【css】基础(一)
  • springboot415社区网格化管理平台的构建-(论文+源码)_kaic
  • 如何在 Ubuntu 上安装开源监控工具 Uptime Kuma
  • 复习 part one
  • 【工业机器视觉】基于深度学习的水表盘读数识别(3-数据标注与转换)
  • python数据分析之爬虫基础:selenium详细讲解
  • Tips--解决esptool经pyinstaller打包后无法使用的问题
  • Apache DolphinScheduler 限制秒级别的定时调度
  • Oracle 数据库创建用户并分配只读的权限
  • 2个GitHub上最近比较火的Java开源项目
  • 【jvm】为什么要有GC
  • 【Rhino】【Python】根据contour创建地形mesh
  • 蓝桥杯软件赛系列---lesson1
  • NanoLog起步笔记-1
  • 汽车车牌标记支持YOLO,COCO,VOC三种格式标记,4000张图片的数据集
  • leetcode33.搜索旋转排序数组
  • Ansible自动化运维(三)playbook剧本详解
  • 通过PS和Unity制作2D动画之二:IK的使用