-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAnimation.cs
More file actions
144 lines (128 loc) · 4.94 KB
/
Animation.cs
File metadata and controls
144 lines (128 loc) · 4.94 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using JyDraft.meta;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JyDraft
{
public class Animation
{
// 一个视频/文本动画效果
public string Name { get; set; }
public string EffectId { get; set; }
public string AnimationType { get; set; }
public string ResourceId { get; set; }
public long Start { get; set; }
public long Duration { get; set; }
public bool IsVideoAnimation { get; set; }
public Animation(AnimationMeta animationMeta, long start, long duration)
{
Name = animationMeta.Title;
EffectId = animationMeta.EffectId;
ResourceId = animationMeta.ResourceId;
Start = start;
Duration = duration;
}
public virtual Dictionary<string, object> ExportJson()
{
return new Dictionary<string, object>
{
{ "anim_adjust_params", null },
{ "platform", "all" },
{ "panel", IsVideoAnimation ? "video" : "" },
{ "material_type", IsVideoAnimation ? "video" : "sticker" },
{ "name", Name },
{ "id", EffectId },
{ "type", AnimationType },
{ "resource_id", ResourceId },
{ "start", Start },
{ "duration", Duration }
// 不导出path和request_id
};
}
}
public class VideoAnimation : Animation
{
public VideoAnimation(AnimationMeta meta, string animationType, long start, long duration)
: base(meta, start, duration)
{
AnimationType = animationType; // "in", "out", "group"
IsVideoAnimation = true;
}
}
public class TextAnimation : Animation
{
public TextAnimation(AnimationMeta meta, string animationType, long start, long duration)
: base(meta, start, duration)
{
AnimationType = animationType; // "in", "out", "loop"
IsVideoAnimation = false;
}
}
public class SegmentAnimations
{
// 附加于某素材上的一系列动画
public string AnimationId { get; set; }
public List<Animation> Animations { get; set; }
public SegmentAnimations()
{
AnimationId = Guid.NewGuid().ToString();
Animations = new List<Animation>();
}
public TimeUtil.Timerange GetAnimationTrange(string animationType)
{
// 获取指定类型的动画的时间范围
foreach (var animation in Animations)
{
if (animation.AnimationType == animationType)
return new TimeUtil.Timerange(animation.Start, animation.Duration);
}
return null;
}
public void AddAnimation(Animation animation)
{
// 不允许添加超过一个同类型的动画(如两个入场动画)
foreach (var ani in Animations)
{
if (ani.AnimationType == animation.AnimationType)
throw new Exception($"当前片段已存在类型为 '{animation.AnimationType}' 的动画");
}
if (animation is VideoAnimation)
{
// 不允许组合动画与出入场动画同时出现
foreach (var ani in Animations)
{
if (ani.AnimationType == "group")
throw new Exception("当前片段已存在组合动画, 此时不能添加其它动画");
}
if (animation.AnimationType == "group" && Animations.Count > 0)
throw new Exception("当前片段已存在动画时, 不能添加组合动画");
}
else if (animation is TextAnimation)
{
foreach (var ani in Animations)
{
if (ani.AnimationType == "loop")
throw new Exception("当前片段已存在循环动画, 若希望同时使用循环动画和入出场动画, 请先添加出入场动画再添加循环动画");
}
}
Animations.Add(animation);
}
public Dictionary<string, object> ExportJson()
{
var animList = new List<Dictionary<string, object>>();
foreach (var animation in Animations)
{
animList.Add(animation.ExportJson());
}
return new Dictionary<string, object>
{
{ "id", AnimationId },
{ "type", "sticker_animation" },
{ "multi_language_current", "none" },
{ "animations", animList }
};
}
}
}