浏览代码

roundig vertex

/main
fzhangtj 6 年前
当前提交
db7e54d8
共有 2 个文件被更改,包括 24 次插入16 次删除
  1. 3
      Assets/UIWidgets/ui/txt/linebreaker.cs
  2. 37
      Assets/UIWidgets/ui/txt/paragraph.cs

3
Assets/UIWidgets/ui/txt/linebreaker.cs


CharacterInfo charInfo;
var result = font.GetCharacterInfo(_text[charIndex], out charInfo, 0, run.style.UnityFontStyle);
Debug.Assert(result, "fail to get character info");
if (_text[charIndex] == '\t')
{
_spaceCount++;

37
Assets/UIWidgets/ui/txt/paragraph.cs


using System;
using System.Collections.Generic;
using System.Text;
using JetBrains.Annotations;
using UnityEngine.Assertions;
using UnityEngine.Experimental.UIElements;
namespace UIWidgets.ui
{

}
newLinePositions.Add(_text.Length);
int runIndex = 0;
StyledRuns.Run lastRun = null;
var lineBreaker = new LineBreaker();
lineBreaker.setup(_text, _runs, _styleRunFonts, (float)_width, _characterPositions, _characterWidths);

font.RequestCharactersInTexture(_text.Substring(run.start, run.end - run.start), run.style.UnityFontSize, run.style.UnityFontStyle);
for (int charIndex = run.start; charIndex < run.end; ++charIndex)
{
CharacterInfo charInfo;
var result = font.GetCharacterInfo(_text[charIndex], out charInfo, run.style.UnityFontSize, run.style.UnityFontStyle);
var position = _characterPositions[charIndex];
vertices[4 * charIndex + 0] = offset + new Vector3(position.x + charInfo.minX, position.y - charInfo.maxY, 0);
vertices[4 * charIndex + 1] = offset + new Vector3(position.x + charInfo.maxX, position.y - charInfo.maxY, 0);
vertices[4 * charIndex + 2] = offset + new Vector3(position.x + charInfo.maxX, position.y - charInfo.minY, 0);
vertices[4 * charIndex + 3] = offset + new Vector3(position.x + charInfo.minX, position.y - charInfo.minY, 0);
CharacterInfo charInfo = new CharacterInfo();
if (_text[charIndex] != '\n')
{
var result = font.GetCharacterInfo(_text[charIndex], out charInfo, run.style.UnityFontSize, run.style.UnityFontStyle);
Debug.Assert(result, "fail to get character info");
var position = _characterPositions[charIndex];
vertices[4 * charIndex + 0] = offset + new Vector3(position.x + charInfo.minX, position.y - charInfo.maxY, 0);
vertices[4 * charIndex + 1] = offset + new Vector3(position.x + charInfo.maxX, position.y - charInfo.maxY, 0);
vertices[4 * charIndex + 2] = offset + new Vector3(position.x + charInfo.maxX, position.y - charInfo.minY, 0);
vertices[4 * charIndex + 3] = offset + new Vector3(position.x + charInfo.minX, position.y - charInfo.minY, 0);
}
else
{
vertices[4 * charIndex + 0] = vertices[4 * charIndex + 1] =
vertices[4 * charIndex + 2] = vertices[4 * charIndex + 3] = offset;
}
if (isWordSpace(_text[charIndex]) || isLineEndSpace(_text[charIndex]) || _text[charIndex] == '\t')
{

triangles[6 * charIndex + 3] = 4 * charIndex + 0;
triangles[6 * charIndex + 4] = 4 * charIndex + 2;
triangles[6 * charIndex + 5] = 4 * charIndex + 3;
}
for (var i = 0; i < vertices.Length; i++)
{
vertices[i].x = (float)Math.Round(vertices[i].x);
vertices[i].y = (float)Math.Round(vertices[i].y);
}
var mesh = new Mesh()

正在加载...
取消
保存