forked from gilzoide/unity-lottie-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLottieAnimationAsset.cs
76 lines (67 loc) · 2.13 KB
/
LottieAnimationAsset.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using UnityEngine;
namespace Gilzoide.LottiePlayer
{
public class LottieAnimationAsset : ScriptableObject
{
[SerializeField] private Vector2Int _size;
[SerializeField] private uint _frameCount;
[SerializeField] private double _frameRate;
[SerializeField] private double _duration;
[Space]
[SerializeField] private string _cacheKey = "";
[SerializeField] private string _resourcePath = "";
[SerializeField, HideInInspector] private string _json;
/// <summary>
/// Key used by rlottie cache system.
/// </summary>
public string CacheKey
{
get => _cacheKey ?? "";
set => _cacheKey = value ?? "";
}
/// <summary>
/// Key used by rlottie cache system.
/// </summary>
public string ResourcePath
{
get => _resourcePath ?? "";
set => _resourcePath = value ?? "";
}
/// <summary>
/// Bytes that compose the Lottie JSON content.
/// </summary>
public string Json
{
get => _json;
set => _json = value ?? "";
}
public Vector2Int Size => _size;
public uint FrameCount => _frameCount;
public double FrameRate => _frameRate;
public double Duration => _duration;
public LottieAnimation CreateAnimation()
{
return new LottieAnimation(Json, CacheKey, ResourcePath);
}
public NativeLottieAnimation CreateNativeAnimation()
{
return new NativeLottieAnimation(Json, CacheKey, ResourcePath);
}
public bool UpdateMetadata()
{
using (var animation = CreateNativeAnimation())
if (animation.IsCreated)
{
_size = animation.GetSize();
_frameCount = animation.GetTotalFrame();
_frameRate = animation.GetFrameRate();
_duration = animation.GetDuration();
return true;
}
else
{
return false;
}
}
}
}