浏览代码

keep moving

/siyaoH-1.17-externalTexture
siyao 3 年前
当前提交
5385a581
共有 4 个文件被更改,包括 60 次插入28 次删除
  1. 14
      Samples/UIWidgetsSamples_2019_4/Assets/Script/SceneTest.cs
  2. 43
      com.unity.uiwidgets/Runtime/rendering/texture.cs
  3. 16
      com.unity.uiwidgets/Runtime/scheduler/binding.cs
  4. 15
      com.unity.uiwidgets/Runtime/widgets/texture.cs

14
Samples/UIWidgetsSamples_2019_4/Assets/Script/SceneTest.cs


class ExampleState : State<ExampleApp>
{
private float frame = 0;
public override Widget build(BuildContext context)
{
var text = GameObject.Find("CameraTarget")?.GetComponent<UnityEngine.UI.RawImage>()?.texture;

{
AnimatedLottie.file("wine.json", frame: frame, curve: Curves.linear),
new Container(width: 100, height: 100, child:new Texture(texture: text)),
new GestureDetector(
onTap: () => { setState(() => { frame += 1; }); },
child: new Container(
color: Color.black,
padding: EdgeInsets.symmetric(20, 20),
child: new Text("Click Me",
style: new TextStyle(fontWeight: FontWeight.w700))
)
)
new Container(width: 100, height: 100, child: new Texture(texture: text)),
}
)
);

43
com.unity.uiwidgets/Runtime/rendering/texture.cs


using System;
using System.Reflection;
using Unity.UIWidgets.async;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.ui;
using UnityEngine;
using Rect = Unity.UIWidgets.ui.Rect;

public TextureBox(int? textureId) {
public TextureBox(int? textureId, Texture texture) {
_texture = texture;
Texture _texture;
public int? textureId {
get { return _textureId; }
set {

}
int? _textureId;
Timer _timer;
bool _frameCallbackScheduled;
protected override bool sizedByParent {
get { return true; }

protected override bool hitTestSelf(Offset position) {
return true;
}
void _scheduleAppFrame() {
if (_frameCallbackScheduled || textureId == null) {
return;
}
_frameCallbackScheduled = true;
SchedulerBinding.instance.scheduleFrameCallback(_handleAppFrame);
}
void _handleAppFrame(TimeSpan timestamp) {
_frameCallbackScheduled = false;
if (textureId == null) {
return;
}
TimeSpan delay = TimeSpan.Zero;
delay = new TimeSpan((long) (delay.Ticks * scheduler_.timeDilation));
// TODO: time dilation
_timer = Timer.create(delay, () => _scheduleAppFrame());
}
if (_texture != null) {
markNeedsLayout();
SchedulerBinding.instance.scheduleFrameCallback(_handleAppFrame);
if (_texture.GetNativeTexturePtr() != IntPtr.Zero) {
_textureId = UIWidgetsPanelWrapper.current.registerTexture(_texture);
}
}
_scheduleAppFrame();
context.addLayer(new TextureLayer(
rect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height),
textureId: _textureId.Value

16
com.unity.uiwidgets/Runtime/scheduler/binding.cs


Window.instance.scheduleFrame();
hasScheduledFrame = true;
onFrameRateSpeedUp();
frameCoolDownTimer?.cancel();
frameCoolDownTimer = Timer.create(_coolDownDelay,
() => {
onFrameRateCoolDown();
frameCoolDownTimer = null;
}
);
// onFrameRateSpeedUp();
// frameCoolDownTimer?.cancel();
// frameCoolDownTimer = Timer.create(_coolDownDelay,
// () => {
// onFrameRateCoolDown();
// frameCoolDownTimer = null;
// }
// );
}
public const int defaultMaxRenderFrameInterval = 200;

15
com.unity.uiwidgets/Runtime/widgets/texture.cs


using System;
using Unity.UIWidgets.async;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.scheduler;
using UnityEngine;
namespace Unity.UIWidgets.widgets {
public class Texture : LeafRenderObjectWidget {

D.assert(textureId != null);
this.textureId = textureId;
this.texture = texture;
if (texture != null && texture.GetNativeTexturePtr() == IntPtr.Zero) {
this.textureId = null;
}
else {
if (texture != null && texture.GetNativeTexturePtr() != IntPtr.Zero) {
this.textureId = UIWidgetsPanelWrapper.current.registerTexture(texture);
}
}

public override RenderObject createRenderObject(BuildContext context) {
return new TextureBox(textureId: textureId);
return new TextureBox(textureId: textureId, texture);;
public override bool Equals(object obj) {
return false;
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
((TextureBox) renderObject).textureId = textureId;
}
正在加载...
取消
保存