siyao
4 年前
当前提交
191e6987
共有 16 个文件被更改,包括 1393 次插入 和 6 次删除
-
28Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs
-
2com.unity.uiwidgets/Runtime/rendering/view.cs
-
31com.unity.uiwidgets/Runtime/ui2/painting.cs
-
4com.unity.uiwidgets/Runtime/widgets/basic.cs
-
2engine/Build.bee.cs
-
7Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/confetti.json.meta
-
1001Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/test.gif
-
7Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/test.gif.meta
-
1Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/wine.json
-
7Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/wine.json.meta
-
132com.unity.uiwidgets/Runtime/rendering/lottie.cs
-
3com.unity.uiwidgets/Runtime/rendering/lottie.cs.meta
-
104com.unity.uiwidgets/Runtime/widgets/LottiePainter.cs
-
3com.unity.uiwidgets/Runtime/widgets/LottiePainter.cs.meta
-
41engine/src/lib/ui/painting/skottie.cc
-
26engine/src/lib/ui/painting/skottie.h
|
|||
fileFormatVersion: 2 |
|||
guid: ac26747b511ae1e42b7ee598ca4fc76d |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/test.gif
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: d0c98e9a4446a81498786934f0bb4268 |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/wine.json
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: e6c5720c879142e49a96f1d129c9a492 |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d638e264913843d89da562fca3c33484 |
|||
timeCreated: 1605844378 |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 719affe0aa514bbca2666a67eedd57a0 |
|||
timeCreated: 1605658320 |
|
|||
#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
|
|
|||
#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 |
撰写
预览
正在加载...
取消
保存
Reference in new issue