OnPopulateMesh

PopulateWithErrors

https://img-blog.csdnimg.cn/20210114201020265.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Z6dGZ6dGZ6dA==,size_16,color_FFFFFF,t_70

TextGenerator用于生成用于渲染的文本,同时会缓存顶点、字符信息和行信息,以便节省内存。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Font font;
    void Start()
    {
        TextGenerationSettings settings = new TextGenerationSettings();
        settings.textAnchor = TextAnchor.MiddleCenter;
        settings.color = Color.red;
        settings.generationExtents = new Vector2(500.0F, 200.0F);
        settings.pivot = Vector2.zero;
        settings.richText = true;
        settings.font = font;
        settings.fontSize = 32;
        settings.fontStyle = FontStyle.Normal;
        settings.verticalOverflow = VerticalWrapMode.Overflow;
        TextGenerator generator = new TextGenerator();
        generator.Populate("I am a string", settings);
        Debug.Log("I generated: " + generator.vertexCount + " verts!");
    }
}

https://img-blog.csdnimg.cn/20210114201522886.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Z6dGZ6dGZ6dA==,size_16,color_FFFFFF,t_70

BaseMeshEffect

继承自UIBehaviour, IMeshModifier IMeshModifier:提供ModifyMesh接口,调用流:在Graphic中被调用

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e51386b2-e775-4356-b29e-d146b1facdae/Untitled.png

Shadow

给图像添加一个外轮廓,就是阴影效果

 protected void ApplyShadowZeroAlloc(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
  {
      UIVertex vt;

      var neededCapacity = verts.Count + end - start;
      if (verts.Capacity < neededCapacity)
          verts.Capacity = neededCapacity;

      for (int i = start; i < end; ++i)
      {
          vt = verts[i];
          verts.Add(vt);

          Vector3 v = vt.position;
          v.x += x;
          v.y += y;
          vt.position = v;
          var newColor = color;
          if (m_UseGraphicAlpha)
              newColor.a = (byte)((newColor.a * verts[i].color.a) / 255);
          vt.color = newColor;
          verts[i] = vt;
      }
  }

  /// <summary>
  /// Duplicate vertices from start to end and turn them into shadows with the given offset.
  /// </summary>
  /// <param name="verts">Vert list to copy</param>
  /// <param name="color">Shadow color</param>
  /// <param name="start">The start index in the verts list</param>
  /// <param name="end">The end index in the vers list</param>
  /// <param name="x">The shadows x offset</param>
  /// <param name="y">The shadows y offset</param>
  protected void ApplyShadow(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
  {
      ApplyShadowZeroAlloc(verts, color, start, end, x, y);
  }

  public override void ModifyMesh(VertexHelper vh)
  {
      if (!IsActive())
          return;

      var output = ListPool<UIVertex>.Get();
      vh.GetUIVertexStream(output);

      ApplyShadow(output, effectColor, 0, output.Count, effectDistance.x, effectDistance.y);
      vh.Clear();
      vh.AddUIVertexTriangleStream(output);
      ListPool<UIVertex>.Release(output);
  }
}

ModifyMesh

用于修改网格的调用。当图形正在填充网格时被调用。

https://img-blog.csdnimg.cn/20210114205813591.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Z6dGZ6dGZ6dA==,size_16,color_FFFFFF,t_70

GetUIVertexStream

获取所有顶点数据

ApplyShadow

复制一遍所有顶点,修改复制出来顶点的x,y 加上effectDistance偏移量,修改颜色color,加入顶点数据