浏览代码

Merge branch 'master' into 'master'

Master

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!89
/main
Shenhua Gu 6 年前
当前提交
a468dcff
共有 6 个文件被更改,包括 74 次插入34 次删除
  1. 32
      Runtime/ui/painting/canvas_impl.cs
  2. 12
      Runtime/ui/painting/canvas_shader.cs
  3. 2
      Runtime/ui/painting/tessellation_generator.cs
  4. 57
      Runtime/ui/painting/txt/mesh_generator.cs
  5. 3
      Runtime/ui/txt/wordbreaker.cs
  6. 2
      Runtime/widgets/binding.cs

32
Runtime/ui/painting/canvas_impl.cs


var matrix = new Matrix3(state.matrix);
matrix.preTranslate(offset.dx, offset.dy);
var mesh = MeshGenerator.generateMesh(textBlob, scale)?.transform(matrix);
if (mesh == null) {
return;
}
var mesh = new TextBlobMesh(textBlob, scale, matrix);
// request font texture so text mesh could be generated correctly
var style = textBlob.style;
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale);
var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize);
font.RequestCharactersInTexture(subText, fontSizeToLoad, style.UnityFontStyle);
if (!this._applyClip(mesh.bounds)) {
if (!this._applyClip(textBlob.bounds)) {
return;
}

if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {
this._drawWithMaskFilter(mesh.bounds, drawMesh, paint, paint.maskFilter);
this._drawWithMaskFilter(textBlob.bounds, drawMesh, paint, paint.maskFilter);
return;
}

public void flush(Picture picture) {
this._reset();
this._drawPicture(picture, false);
D.assert(this._layers.Count == 1);

// clear triangles first in order to bypass validation in SetVertices.
cmd.meshObj.SetTriangles((int[]) null, 0, false);
cmd.meshObj.SetVertices(cmd.mesh.vertices);
cmd.meshObj.SetTriangles(cmd.mesh.triangles, 0, false);
cmd.meshObj.SetUVs(0, cmd.mesh.uv);
MeshMesh mesh = cmd.mesh;
if (cmd.textMesh != null) {
mesh = cmd.textMesh.resovleMesh();
}
cmd.meshObj.SetVertices(mesh.vertices);
cmd.meshObj.SetTriangles(mesh.triangles, 0, false);
cmd.meshObj.SetUVs(0, mesh.uv);
if (cmd.mesh.matrix == null) {
if (mesh.matrix == null) {
cmd.properties.SetFloatArray(RenderDraw.matId, cmd.mesh.matrix.fMat);
cmd.properties.SetFloatArray(RenderDraw.matId, mesh.matrix.fMat);
}
cmdBuf.DrawMesh(cmd.meshObj, RenderDraw.idMat, cmd.material, 0, cmd.pass, cmd.properties);

internal class RenderDraw {
public MeshMesh mesh;
public TextBlobMesh textMesh;
public int pass;
public MaterialPropertyBlock properties;
public RenderLayer layer;

12
Runtime/ui/painting/canvas_shader.cs


public static PictureFlusher.RenderDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
MeshMesh mesh, Texture tex) {
return texAlpha(layer, paint, mesh, null, tex);
}
public static PictureFlusher.RenderDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
TextBlobMesh textMesh, Texture tex) {
return texAlpha(layer, paint, null, textMesh, tex);
}
public static PictureFlusher.RenderDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
MeshMesh mesh, TextBlobMesh textMesh, Texture tex) {
var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);
_getShaderPassAndProps(layer, paint, mesh, 1.0f, out var pass, out var props);
tex.filterMode = paint.filterMode;

return new PictureFlusher.RenderDraw {
mesh = mesh,
textMesh = textMesh,
pass = pass,
material = mat,
properties = props,

2
Runtime/ui/painting/tessellation_generator.cs


}
public void touch(long timeTolive = 5) {
this._timeToLive = timeTolive + MeshGenerator.frameCount;
this._timeToLive = timeTolive + TextBlobMesh.frameCount;
}
}

57
Runtime/ui/painting/txt/mesh_generator.cs


}
public void touch(long timeTolive = 5) {
this._timeToLive = timeTolive + MeshGenerator.frameCount;
this._timeToLive = timeTolive + TextBlobMesh.frameCount;
static class MeshGenerator {
class TextBlobMesh {
readonly TextBlob _textBlob;
readonly float _scale;
readonly Matrix3 _transform;
MeshMesh _mesh;
bool _resolved;
public TextBlobMesh(TextBlob textBlob, float scale, Matrix3 transform) {
this._textBlob = textBlob;
this._scale = scale;
this._transform = transform;
}
public static long frameCount {
get { return _frameCount; }
}

}
}
public static MeshMesh generateMesh(TextBlob textBlob, float scale) {
var style = textBlob.style;
public MeshMesh resovleMesh() {
if (this._resolved) {
return this._mesh;
}
this._resolved = true;
var style = this._textBlob.style;
var key = new MeshKey(textBlob.instanceId, scale);
var key = new MeshKey(this._textBlob.instanceId, this._scale);
return meshInfo.mesh;
this._mesh = meshInfo.mesh.transform(this._transform);
return this._mesh;
var length = textBlob.textSize;
var text = textBlob.text;
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale);
var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize);
font.RequestCharactersInTexture(subText, fontSizeToLoad, style.UnityFontStyle);
var length = this._textBlob.textSize;
var text = this._textBlob.text;
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * this._scale);
var ch = text[charIndex + textBlob.textOffset];
var ch = text[charIndex + this._textBlob.textOffset];
var position = textBlob.positions[charIndex];
var position = this._textBlob.positions[charIndex];
if (LayoutUtils.isWordSpace(ch) || LayoutUtils.isLineEndSpace(ch) || ch == '\t') {
continue;
}

var minX = charInfo.minX / scale;
var maxX = charInfo.maxX / scale;
var minY = charInfo.minY / scale;
var maxY = charInfo.maxY / scale;
var minX = charInfo.minX / this._scale;
var maxX = charInfo.maxX / this._scale;
var minY = charInfo.minY / this._scale;
var maxY = charInfo.maxY / this._scale;
var baseIndex = vertices.Count;

MeshMesh mesh = vertices.Count > 0 ? new MeshMesh(null, vertices, triangles, uv) : null;
_meshes[key] = new MeshInfo(key, mesh, fontInfo.textureVersion);
return mesh;
this._mesh = mesh.transform(this._transform);
return this._mesh;
}
}
}

3
Runtime/ui/txt/wordbreaker.cs


break;
}
var currentType = WordSeparate.classifyChar(this._text, this._current + this._offset);
if (currentType != preType) {
if ((currentType == WordSeparate.characterType.WhiteSpace)
!= (preType == WordSeparate.characterType.WhiteSpace)) {
break;
}
preType = currentType;

2
Runtime/widgets/binding.cs


Window.instance.onLocaleChanged += this.handleLocaleChanged;
this.widgetInspectorService = new WidgetInspectorService(this);
this.addPersistentFrameCallback((duration) => {
MeshGenerator.tickNextFrame();
TextBlobMesh.tickNextFrame();
TessellationGenerator.tickNextFrame();
});
}

正在加载...
取消
保存