当前位置: 首页> 健康> 母婴 > 自己可以开发一个app_100个闲置商标转让平台_seo网站关键词优化报价_企业的互联网推广

自己可以开发一个app_100个闲置商标转让平台_seo网站关键词优化报价_企业的互联网推广

时间:2025/7/20 21:45:10来源:https://blog.csdn.net/qq_39574690/article/details/144953889 浏览次数:0次
自己可以开发一个app_100个闲置商标转让平台_seo网站关键词优化报价_企业的互联网推广

相关技术:Text、TextMesh、Rigidbody(刚体)、BoxCollider(碰撞体)、TextGenerator、文本网格、文字网格

 

原理:使用UGUI Text获取其文字的每个字符网格坐标,转世界坐标生成对应的3D文本(TextMesh)并挂上刚体、碰撞体实现掉落。

UGUI Text直接挂Canvas(World Space) 将它挪到镜头前,然后我是调整它的透明度为0的(不会影响网格生成),并挂载Gravity3DText组件,Gravity3DText组件参数拖拽自身Canvas和一个TextMesh物体预制体(3D文本),运行游戏后点击空格生成3D文本

预制体组件情况:

UGUI Text物体组件情况:

地板物体:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Gravity3DText : MonoBehaviour
{public Canvas canvas;public GameObject gravity3DTextPrefab;private Text textMesh;private List<GameObject> tempTextList;public class CharData{public Vector3 pos;public Vector2 size;}void Start(){tempTextList = new List<GameObject>();textMesh = GetComponent<Text>();textMesh.GraphicUpdateComplete();}public void Update(){if (Input.GetKeyDown(KeyCode.Space)){string textStr = textMesh.text;int textLength = textStr.Length;TextGenerator textGenerator = new TextGenerator(textLength);Vector2 size = textMesh.rectTransform.rect.size;textGenerator.Populate(textStr, textMesh.GetGenerationSettings(size));List<UIVertex> vertexList = textGenerator.verts as List<UIVertex>;            List<CharData> charDataList = new List<CharData>();for (int i = 0; i <= vertexList.Count - 4; i += 4){CharData charData = new CharData();Vector3 pos1 = vertexList[i].position;Vector3 pos2 = vertexList[i + 1].position;Vector3 pos3 = vertexList[i + 2].position;Vector3 pos4 = vertexList[i + 3].position;Vector3 pos = (pos1 + pos2 + pos3 + pos4) / 4.0f;pos /= canvas.scaleFactor;charData.pos = pos;Vector3 charMinPos = Vector3.Min(pos1, pos2);charMinPos = Vector3.Min(charMinPos, pos3);charMinPos = Vector3.Min(charMinPos, pos4);Vector3 charMaxPos = Vector3.Max(pos1, pos2);charMaxPos = Vector3.Max(charMaxPos, pos3);charMaxPos = Vector3.Max(charMaxPos, pos4);charData.size = new Vector2(charMaxPos.x - charMinPos.x, charMaxPos.y - charMinPos.y);charDataList.Add(charData);}//统一字体大小            float sameY = transform.localPosition.y;string trimStr = textStr.Replace(" ", "");Debug.Log("trimStr:" + trimStr);int subMeshCount = Mathf.Min(textMesh.text.Length, charDataList.Count);for (int i = 0; i < subMeshCount; i++){CharData charData = charDataList[i];Vector3 pos = transform.TransformPoint(charData.pos);pos.y = sameY;Debug.Log($"第{i + 1}个字,中心点:{pos}, size:{charData.size}, char:{trimStr[i]}");GameObject tempTextGo = GameObject.Instantiate(gravity3DTextPrefab);Transform tempTextTrans = tempTextGo.transform;tempTextTrans.position = pos;TextMesh tempTextMesh = tempTextGo.GetComponent<TextMesh>();tempTextMesh.text = trimStr[i].ToString();tempTextMesh.fontSize = textMesh.fontSize * 5;tempTextMesh.characterSize = 10 / 5; //minSize;tempTextList.Add(tempTextGo);}}}private void OnDestroy(){foreach (var v in tempTextList){GameObject.Destroy(v);}tempTextList.Clear();}
}
关键字:自己可以开发一个app_100个闲置商标转让平台_seo网站关键词优化报价_企业的互联网推广

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: