using UnityEngine; using UnityEngine.UI; using Text = UnityEngine.UI.Text;
[RequireComponent(typeof(Text))] public class TextFormatting : BaseMeshEffect { [SerializeField] [Header("多行对齐方式:默认UpperLeft")] private TextAnchor multiline = TextAnchor.UpperLeft; [SerializeField] [Header("单行对齐方式:默认MiddleCenter")] private TextAnchor singleLine = TextAnchor.MiddleCenter; private Text textComponent; private string content = ""; private float textCompentWidth = 0; protected override void OnEnable() { base.OnEnable(); if (textComponent == null) { textComponent = GetComponent<Text>(); } textCompentWidth = textComponent.rectTransform.rect.width; textComponent.RegisterDirtyVerticesCallback(ReplaceSpace); } public override void ModifyMesh(VertexHelper vh) { if (!IsActive())