TonyViT / CurvedTextMeshPro

A simple plugin to make curved TextMeshPro texts using a mathematical function
MIT License
206 stars 27 forks source link

Use the OnPreRenderText event! #6

Open CharlieHess opened 7 months ago

CharlieHess commented 7 months ago

Rather than using Update and comparing properties every frame, this whole thing can be simplified using the TextMeshPro.OnPreRenderText event, which was purpose-built for modifications like this. Here's a forum post from the creator of TextMeshPro explaining why this event was added and how it covers this use case. Essentially you can make modifications to the vertices "just in time" and avoid calling ForceMeshUpdate and UpdateVertexData.

I have adapted this code and written a simpler version, which you can find here. My version:

  1. Trims all the Update and property comparison logic using the OnPreRenderText event
  2. Removes unnecessary properties arcDegrees and offsetAngle—if you want to increase the number of degrees the text arc occupies, use the pre-existing character spacing attributes on TextMeshPro, and if you want to control the angle of rotation, simply use a rotation on the z-axis of the parent transform
  3. Does away with the inheritance scheme as I had no need for TextProOnAExp
bleppie commented 1 month ago

Thank you, this is definitely cleaner.