浏览代码

add texture layer.

/main
kg 6 年前
当前提交
c0dc9c77
共有 10 个文件被更改,包括 222 次插入1 次删除
  1. 35
      Runtime/rendering/layer.cs
  2. 19
      Runtime/ui/compositing.cs
  3. 4
      Runtime/ui/window.cs
  4. 2
      Runtime/widgets/app.cs
  5. 51
      Runtime/flow/texture_layer.cs
  6. 11
      Runtime/flow/texture_layer.cs.meta
  7. 58
      Runtime/rendering/texture.cs
  8. 11
      Runtime/rendering/texture.cs.meta
  9. 21
      Runtime/widgets/texture.cs
  10. 11
      Runtime/widgets/texture.cs.meta

35
Runtime/rendering/layer.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using UnityEngine;
using Rect = Unity.UIWidgets.ui.Rect;
namespace Unity.UIWidgets.rendering {
public abstract class Layer : AbstractNodeMixinDiagnosticableTree {

public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Rect>("paint bounds", this.canvasBounds));
}
}
public class TextureLayer : Layer {
public TextureLayer(
Rect rect,
Texture texture,
bool freeze = false
) {
D.assert(rect != null);
D.assert(texture != null);
this.rect = rect;
this.texture = texture;
this.freeze = freeze;
}
public readonly Rect rect;
public readonly Texture texture;
public readonly bool freeze;
internal override flow.Layer addToScene(SceneBuilder builder, Offset layerOffset = null) {
Rect shiftedRect = this.rect.shift(layerOffset);
builder.addTexture(
this.texture,
offset: shiftedRect.topLeft,
width: shiftedRect.width,
height: shiftedRect.height,
freeze: this.freeze
);
return null;
}
}

19
Runtime/ui/compositing.cs


using System;
using Unity.UIWidgets.flow;
using Unity.UIWidgets.foundation;
using UnityEngine;
namespace Unity.UIWidgets.ui {
public class SceneBuilder {

this._currentLayer.add(layer);
}
public void addTexture(
Texture texture,
Offset offset,
float width,
float height,
bool freeze) {
if (this._currentLayer == null) {
return;
}
var layer = new TextureLayer();
layer.offset = offset;
layer.size = new Size(width, height);
layer.texture = texture;
layer.freeze = freeze;
this._currentLayer.add(layer);
}
public void addPerformanceOverlay(int enabledOptions, Rect bounds) {
if (this._currentLayer == null) {
return;

4
Runtime/ui/window.cs


public abstract void scheduleFrame(bool regenerateLayerTree = true);
public void textureFrameAvailable() {
this.scheduleFrame(false);
}
public abstract void render(Scene scene);
public abstract void scheduleMicrotask(Action callback);

2
Runtime/widgets/app.cs


var name = settings.name;
var pageContentBuilder = name == Navigator.defaultRouteName && this.widget.home != null
? context => this.widget.home
: this.widget.routes[name];
: this.widget.routes.getOrDefault(name);
if (pageContentBuilder != null) {
D.assert(this.widget.pageRouteBuilder != null,

51
Runtime/flow/texture_layer.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;
using Rect = Unity.UIWidgets.ui.Rect;
namespace Unity.UIWidgets.flow {
public class TextureLayer : Layer {
Offset _offset = Offset.zero;
public Offset offset {
set { this._offset = value ?? Offset.zero; }
}
Size _size;
public Size size {
set { this._size = value; }
}
Texture _texture;
public Texture texture {
set { this._texture = value; }
}
bool _freeze = false;
public bool freeze {
set { this._freeze = value; }
}
public override void preroll(PrerollContext context, Matrix3 matrix) {
this.paintBounds = Rect.fromLTWH(
this._offset.dx, this._offset.dy, this._size.width, this._size.height);
}
public override void paint(PaintContext context) {
D.assert(this.needsPainting);
if (this._texture == null) {
return;
}
var image = new Image(this._texture, noDispose: true);
var canvas = context.canvas;
canvas.drawImageRect(image, this.paintBounds, new Paint());
}
}
}

11
Runtime/flow/texture_layer.cs.meta


fileFormatVersion: 2
guid: 58b198e3ad2fc48dd999a86390611092
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

58
Runtime/rendering/texture.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;
using Rect = Unity.UIWidgets.ui.Rect;
namespace Unity.UIWidgets.rendering {
public class TextureBox : RenderBox {
public TextureBox(Texture texture) {
D.assert(texture != null);
this._texture = texture;
}
public Texture texture {
get { return this._texture; }
set {
D.assert(value != null);
if (value != this._texture) {
this._texture = value;
this.markNeedsPaint();
}
}
}
Texture _texture;
protected override bool sizedByParent {
get { return true; }
}
protected override bool alwaysNeedsCompositing {
get { return true; }
}
public override bool isRepaintBoundary {
get { return true; }
}
protected override void performResize() {
this.size = this.constraints.biggest;
}
protected override bool hitTestSelf(Offset position) {
return true;
}
public override void paint(PaintingContext context, Offset offset) {
if (this._texture == null) {
return;
}
context.addLayer(new TextureLayer(
rect: Rect.fromLTWH(offset.dx, offset.dy, this.size.width, this.size.height),
texture: this._texture
));
}
}
}

11
Runtime/rendering/texture.cs.meta


fileFormatVersion: 2
guid: 6752d156317e44036a1924d168ded7e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

21
Runtime/widgets/texture.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
namespace Unity.UIWidgets.widgets {
public class Texture : LeafRenderObjectWidget {
public Texture(Key key, UnityEngine.Texture texture) : base(key: key) {
D.assert(texture != null);
this.texture = texture;
}
public readonly UnityEngine.Texture texture;
public override RenderObject createRenderObject(BuildContext context) {
return new TextureBox(texture: this.texture);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
((TextureBox) renderObject).texture = this.texture;
}
}
}

11
Runtime/widgets/texture.cs.meta


fileFormatVersion: 2
guid: 5de15949323be4d0eb8faec4015cd792
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存