浏览代码

lottie

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
191e6987
共有 16 个文件被更改,包括 1393 次插入6 次删除
  1. 28
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs
  2. 2
      com.unity.uiwidgets/Runtime/rendering/view.cs
  3. 31
      com.unity.uiwidgets/Runtime/ui2/painting.cs
  4. 4
      com.unity.uiwidgets/Runtime/widgets/basic.cs
  5. 2
      engine/Build.bee.cs
  6. 7
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/confetti.json.meta
  7. 1001
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/test.gif
  8. 7
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/test.gif.meta
  9. 1
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/wine.json
  10. 7
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/wine.json.meta
  11. 132
      com.unity.uiwidgets/Runtime/rendering/lottie.cs
  12. 3
      com.unity.uiwidgets/Runtime/rendering/lottie.cs.meta
  13. 104
      com.unity.uiwidgets/Runtime/widgets/LottiePainter.cs
  14. 3
      com.unity.uiwidgets/Runtime/widgets/LottiePainter.cs.meta
  15. 41
      engine/src/lib/ui/painting/skottie.cc
  16. 26
      engine/src/lib/ui/painting/skottie.h

28
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs


using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;

using FontStyle = Unity.UIWidgets.ui.FontStyle;
using Image = Unity.UIWidgets.widgets.Image;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
using ui_ = Unity.UIWidgets.widgets.ui_;

{
int counter;
private float frame = 0;
public override Widget build(BuildContext context)
{
return new Container(

{
AnimatedLottie.file("wine.json", frame: frame, curve: Curves.linear),
new Container(
width: 100,
height: 100,
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8))
),
child: Image.file("test.gif", gaplessPlayback: true)
),
new Container(
width: 200,
height: 100,
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8))
),
child: Image.network(
"https://unity-cn-cms-prd-1254078910.cos.ap-shanghai.myqcloud.com/assetstore-cms-media/img-7dfe215f-0075-4f9c-9b5a-be5ee88b866b",
gaplessPlayback: true)
),
new Text("Counter: " + counter,
style: new TextStyle(fontSize: 18, fontWeight: FontWeight.w100)),
new Text("Counter: " + counter,

new GestureDetector(
onTap: () =>
{
setState(()
=>
setState(() =>
frame += 1;
});
},
child: new Container(

2
com.unity.uiwidgets/Runtime/rendering/view.cs


public readonly float devicePixelRatio;
public Matrix4 toMatrix() {
return new Matrix4().diagonal3Values(this.devicePixelRatio, this.devicePixelRatio, 0);
return new Matrix4().diagonal3Values(devicePixelRatio, devicePixelRatio, 0);
//return new Matrix4().identity();
}

31
com.unity.uiwidgets/Runtime/ui2/painting.cs


}
}
}
public class Skottie : NativeWrapper {
public Skottie(string path) {
_setPtr(Skottie_Construct(path));
}
protected override void DisposePtr(IntPtr ptr) {
Skottie_Dispose(ptr);
}
public void paint(Canvas canvas, Offset offset, float width, float height, float frame) {
Skottie_Paint(_ptr, canvas._ptr, offset.dx, offset.dy, width, height, frame);
}
public float duration() {
return Skottie_Duration(_ptr);
}
[DllImport(NativeBindings.dllName)]
static extern IntPtr Skottie_Construct(string path);
[DllImport(NativeBindings.dllName)]
static extern void Skottie_Dispose(IntPtr skottie);
[DllImport(NativeBindings.dllName)]
static extern void Skottie_Paint(IntPtr skottie, IntPtr canvas, float x, float y, float width, float height,
float frame);
[DllImport(NativeBindings.dllName)]
static extern float Skottie_Duration(IntPtr skottie);
}
delegate void _Callback<T>(T result);

4
com.unity.uiwidgets/Runtime/widgets/basic.cs


this.repeat = repeat;
this.centerSlice = centerSlice;
this.invertColors = invertColors;
this.filterMode = filterMode;
this.filterQuality = filterQuality;
}

public readonly float scale;
public readonly Color color;
public readonly FilterMode filterMode;
public readonly BlendMode colorBlendMode;
public readonly BoxFit? fit;
public readonly Alignment alignment;

properties.add(new DiagnosticsProperty<Rect>("centerSlice", centerSlice,
defaultValue: foundation_.kNullDefaultValue));
properties.add(new DiagnosticsProperty<bool>("invertColors", invertColors));
properties.add(new EnumProperty<FilterMode>("filterMode", filterMode));
properties.add(new EnumProperty<FilterQuality>("filterMode", filterQuality));
}
}

2
engine/Build.bee.cs


"src/lib/ui/painting/shader.h",
"src/lib/ui/painting/single_frame_codec.cc",
"src/lib/ui/painting/single_frame_codec.h",
"src/lib/ui/painting/skottie.cc",
"src/lib/ui/painting/skottie.h",
"src/lib/ui/painting/vertices.cc",
"src/lib/ui/painting/vertices.h",

7
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/confetti.json.meta


fileFormatVersion: 2
guid: ac26747b511ae1e42b7ee598ca4fc76d
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/test.gif
文件差异内容过多而无法显示
查看文件

7
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/test.gif.meta


fileFormatVersion: 2
guid: d0c98e9a4446a81498786934f0bb4268
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/wine.json
文件差异内容过多而无法显示
查看文件

7
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/wine.json.meta


fileFormatVersion: 2
guid: e6c5720c879142e49a96f1d129c9a492
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

132
com.unity.uiwidgets/Runtime/rendering/lottie.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.rendering {
public class RenderLottie : RenderBox {
public RenderLottie(
Skottie skottie,
float? width = null,
float? height = null,
float scale = 1.0f,
float frame = 0
) {
_width = width;
_height = height;
_scale = scale;
_skottie = skottie;
_frame = frame;
_duration = skottie.duration();
}
Skottie _skottie;
float _frame = 0;
float _duration = 0;
public float frame {
get { return _frame; }
set {
while (value > _duration) {
value -= _duration;
}
if (value == _frame) {
return;
}
_frame = value;
markNeedsLayout();
}
}
float? _width;
public float? width {
get { return _width; }
set {
if (value == _width) {
return;
}
_width = value;
markNeedsLayout();
}
}
float? _height;
public float? height {
get { return _height; }
set {
if (value == _height) {
return;
}
_height = value;
markNeedsLayout();
}
}
float _scale;
public float scale {
get { return _scale; }
set {
if (value == _scale) {
return;
}
_scale = value;
markNeedsLayout();
}
}
Size _sizeForConstraints(BoxConstraints constraints) {
constraints = BoxConstraints.tightFor(
_width,
_height
).enforce(constraints);
return constraints.smallest;
}
protected override float computeMinIntrinsicWidth(float height) {
D.assert(height >= 0.0);
if (_width == null && _height == null) {
return 0.0f;
}
return _sizeForConstraints(BoxConstraints.tightForFinite(height: height)).width;
}
protected override float computeMaxIntrinsicWidth(float height) {
D.assert(height >= 0.0);
return _sizeForConstraints(BoxConstraints.tightForFinite(height: height)).width;
}
protected override float computeMinIntrinsicHeight(float width) {
D.assert(width >= 0.0);
if (_width == null && _height == null) {
return 0.0f;
}
return _sizeForConstraints(BoxConstraints.tightForFinite(width: width)).height;
}
protected internal override float computeMaxIntrinsicHeight(float width) {
D.assert(width >= 0.0);
return _sizeForConstraints(BoxConstraints.tightForFinite(width: width)).height;
}
protected override bool hitTestSelf(Offset position) {
return true;
}
protected override void performLayout() {
size = _sizeForConstraints(constraints);
}
public override void paint(PaintingContext context, Offset offset) {
_skottie.paint(context.canvas, offset, _width ?? 0, _height ?? 0, _frame);
}
}
}

3
com.unity.uiwidgets/Runtime/rendering/lottie.cs.meta


fileFormatVersion: 2
guid: d638e264913843d89da562fca3c33484
timeCreated: 1605844378

104
com.unity.uiwidgets/Runtime/widgets/LottiePainter.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using UnityEngine;
using Path = System.IO.Path;
namespace Unity.UIWidgets.widgets {
public class Lottie : StatefulWidget {
public Skottie _skottie = null;
public float _frame = 0;
public Lottie(string path, float frame) {
D.assert(path != null);
_skottie = new Skottie(Path.Combine(Application.streamingAssetsPath, path));
_frame = frame;
}
public override State createState() {
return new LottieState();
}
}
public class LottieState : State<Lottie> {
public override Widget build(BuildContext context) {
return new LottieRenderObjectWidget(widget._skottie, widget._frame);
}
}
public class LottieRenderObjectWidget : LeafRenderObjectWidget {
Skottie _anime;
float _frame;
float _duration;
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
base.updateRenderObject(context, renderObject);
var a = (RenderLottie) renderObject;
a.frame = _frame*_duration;
}
public LottieRenderObjectWidget(Skottie anime, float frame) {
_anime = anime;
_frame = frame;
_duration = anime.duration();
}
public override RenderObject createRenderObject(BuildContext context) {
return new RenderLottie(_anime, 100, 100, frame: _frame);
}
}
public class AnimatedLottie : ImplicitlyAnimatedWidget {
public Skottie _skottie = null;
public float _frame = 0;
public AnimatedLottie(
string path,
Key key = null,
Curve curve = null,
TimeSpan? duration = null,
float frame = 0
) :base(key: key, curve: curve, duration: duration){
_skottie = new Skottie(Path.Combine(Application.streamingAssetsPath, path));
_frame = frame;
}
AnimatedLottie(
Skottie skottie,
Key key = null,
Curve curve = null,
TimeSpan? duration = null,
float frame = 0
) :base(key: key, curve: curve, duration: duration){
_skottie = skottie;
_frame = frame;
}
public static AnimatedLottie file(string path, Key key = null, Curve curve = null, TimeSpan? duration = null,
float frame = 0) {
var skottie = new Skottie(Path.Combine(Application.streamingAssetsPath, path));
duration = duration ?? TimeSpan.FromSeconds(skottie.duration());
return new AnimatedLottie(skottie, key, curve, duration, frame);
}
public override State createState() {
return new _AnimatedLottieState();
}
}
class _AnimatedLottieState : AnimatedWidgetBaseState<AnimatedLottie> {
FloatTween frame;
protected override void forEachTween(TweenVisitor visitor) {
frame = (FloatTween) visitor.visit(this, frame, widget._frame,
(value) => new FloatTween(begin: value, value));
}
public override Widget build(BuildContext context) {
return new LottieRenderObjectWidget(widget._skottie, frame.lerp(animation.value));
}
}
}

3
com.unity.uiwidgets/Runtime/widgets/LottiePainter.cs.meta


fileFormatVersion: 2
guid: 719affe0aa514bbca2666a67eedd57a0
timeCreated: 1605658320

41
engine/src/lib/ui/painting/skottie.cc


#include "skottie.h"
#include "lib/ui/ui_mono_state.h"
namespace uiwidgets {
fml::RefPtr<Skottie> Skottie::Create(char* path) {
sk_sp<skottie::Animation> animation_ = skottie::Animation::MakeFromFile(path);
return fml::MakeRefCounted<Skottie>(animation_);
}
Skottie::Skottie(sk_sp<skottie::Animation> animation) {
animation_ = animation;
}
void Skottie::paint(Canvas* canvas, float x, float y, float width, float height,
float frame) {
animation_->seekFrameTime(frame);
SkRect rect = SkRect::MakeXYWH(x, y, width, height);
animation_->render(canvas->canvas(), &rect);
}
float Skottie::duration() { return animation_->duration(); }
UIWIDGETS_API(Skottie*)
Skottie_Construct(char* path) {
fml::RefPtr<Skottie> skottie = Skottie::Create(path);
skottie->AddRef();
return skottie.get();
}
UIWIDGETS_API(void)
Skottie_Dispose(Skottie* ptr) { ptr->Release(); }
UIWIDGETS_API(void)
Skottie_Paint(Skottie* ptr, Canvas* canvas, float x, float y, float width,
float height, float frame) {
ptr->paint(canvas, x, y, width, height, frame);
}
UIWIDGETS_API(float)
Skottie_Duration(Skottie* ptr) { return ptr->duration(); }
} // namespace uiwidgets

26
engine/src/lib/ui/painting/skottie.h


#pragma once
#include "flutter/fml/memory/ref_counted.h"
#include "lib/ui/painting/canvas.h"
#include "modules/skottie/include/Skottie.h"
namespace uiwidgets {
class Skottie : public fml::RefCountedThreadSafe<Skottie> {
FML_FRIEND_MAKE_REF_COUNTED(Skottie);
public:
static fml::RefPtr<Skottie> Create(char* path);
void paint(Canvas* canvas, float x, float y, float width, float height,
float frame);
float duration();
private:
explicit Skottie(sk_sp<skottie::Animation> animation);
sk_sp<skottie::Animation> animation_;
bool is_null;
};
} // namespace uiwidgets
正在加载...
取消
保存