voidModifyText(VertexHelper helper, int i, int charYPos, int charXPos) { //Text 的绘制是每4个顶点绘制一个字符 //按字符顺序取出顶点,则可以获得字符的位置 //并对其进行修改
//取出原来顶点的位置 UIVertex lb = new UIVertex(); helper.PopulateUIVertex(ref lb, i * 4);
UIVertex lt = new UIVertex(); helper.PopulateUIVertex(ref lt, i * 4 + 1);
UIVertex rt = new UIVertex(); helper.PopulateUIVertex(ref rt, i * 4 + 2);
UIVertex rb = new UIVertex(); helper.PopulateUIVertex(ref rb, i * 4 + 3);
//计算文本的中心点 Vector3 center = Vector3.Lerp(lb.position, rt.position, 0.5f);
float x = -charXPos * lineSpace + xOffset; float y = -charYPos * textSpace + yOffset;
//计算字符新位置 Vector3 pos = new Vector3(x, y, 0);
lb.position = lb.position - center + new Vector3(x, y, 0); lt.position = lt.position - center + new Vector3(x, y, 0); rt.position = rt.position - center + new Vector3(x, y, 0); rb.position = rb.position - center + new Vector3(x, y, 0);
helper.SetUIVertex(lb, i * 4); helper.SetUIVertex(lt, i * 4 + 1); helper.SetUIVertex(rt, i * 4 + 2); helper.SetUIVertex(rb, i * 4 + 3); } }