您的位置:首页 > 教育 > 锐评 > 中国有名的设计公司_免费域名证书申请_河南网站关键词优化代理_html网页模板

中国有名的设计公司_免费域名证书申请_河南网站关键词优化代理_html网页模板

2025/4/19 16:47:28 来源:https://blog.csdn.net/qq_40771473/article/details/144343098  浏览:    关键词:中国有名的设计公司_免费域名证书申请_河南网站关键词优化代理_html网页模板
中国有名的设计公司_免费域名证书申请_河南网站关键词优化代理_html网页模板

 效果:

using UnityEngine;
using TMPro;
using Core;[ExecuteInEditMode]
public class TMTextWrap : MonoBehaviour
{private TMP_Text m_TextComponent;public AnimationCurve VertexCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0f));public float AngleMultiplier = 1.0f;public float SpeedMultiplier = 1.0f;public float CurveScale = 1.0f;public bool ForceChange = true;public bool AlwaysChange = false;float m_OldCurveScale;AnimationCurve m_OldCurve;void Awake(){m_TextComponent = gameObject.GetComponent<TMP_Text>();if (AlwaysChange){Log.Error($"{gameObject.name} text wrap set to always change on awake");}}void LateUpdate(){if (NeedChange() || AlwaysChange){WarpText();}}void OnEnable(){ForceChange = true;}bool NeedChange(){if (ForceChange){ForceChange = false;return true;}if (m_TextComponent.havePropertiesChanged)return true;if (Mathf.Abs(m_OldCurveScale - CurveScale) > 0.01f)return true;if (!m_OldCurve.Equals(VertexCurve))return true;return false;}private AnimationCurve CopyAnimationCurve(AnimationCurve curve){AnimationCurve newCurve = new AnimationCurve(curve.keys);return newCurve;}/// <summary>///  Method to curve text along a Unity animation curve./// </summary>/// <param name="textComponent"></param>/// <returns></returns>void WarpText(){VertexCurve.preWrapMode = WrapMode.Clamp;VertexCurve.postWrapMode = WrapMode.Clamp;m_OldCurve = CopyAnimationCurve(VertexCurve);m_OldCurveScale = CurveScale;//Mesh mesh = m_TextComponent.textInfo.meshInfo[0].mesh;Vector3[] vertices;Matrix4x4 matrix;m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.TMP_TextInfo textInfo = m_TextComponent.textInfo;int characterCount = textInfo.characterCount;if (characterCount == 0) return;//vertices = textInfo.meshInfo[0].vertices;//int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex;float boundsMinX = m_TextComponent.bounds.min.x;  //textInfo.meshInfo[0].mesh.bounds.min.x;float boundsMaxX = m_TextComponent.bounds.max.x;  //textInfo.meshInfo[0].mesh.bounds.max.x;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;// Compute the baseline mid point for each characterVector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);//float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f); // Random.Range(-0.25f, 0.25f);// Apply offset to adjust our pivot point.vertices[vertexIndex + 0] += -offsetToMidBaseline;vertices[vertexIndex + 1] += -offsetToMidBaseline;vertices[vertexIndex + 2] += -offsetToMidBaseline;vertices[vertexIndex + 3] += -offsetToMidBaseline;// Compute the angle of rotation for each character based on the animation curvefloat x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.float x1 = x0 + 0.0001f;float y0 = VertexCurve.Evaluate(x0) * CurveScale;float y1 = VertexCurve.Evaluate(x1) * CurveScale;Vector3 horizontal = new Vector3(1, 0, 0);//Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0);Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0);float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;Vector3 cross = Vector3.Cross(horizontal, tangent);float angle = cross.z > 0 ? dot : 360 - dot;matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);vertices[vertexIndex + 0] += offsetToMidBaseline;vertices[vertexIndex + 1] += offsetToMidBaseline;vertices[vertexIndex + 2] += offsetToMidBaseline;vertices[vertexIndex + 3] += offsetToMidBaseline;}// Upload the mesh with the revised informationm_TextComponent.UpdateVertexData();}
}

版权声明:

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

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