-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathInLoopOutAnimation.cs
109 lines (94 loc) · 2.38 KB
/
InLoopOutAnimation.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
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
using CitizenFX.Core;
using CitizenFX.Core.Native;
using static CitizenFX.Core.Native.API;
namespace FRFuel
{
public enum State
{
Starting,
Looping,
Ended
}
public struct Animation
{
public string dict;
public string name;
public Animation(string animationDictionary, string animationName)
{
dict = animationDictionary;
name = animationName;
}
}
public class InLoopOutAnimation
{
protected Animation start;
protected Animation loop;
protected Animation end;
protected State state;
public InLoopOutAnimation(Animation start, Animation loop, Animation end)
{
this.start = start;
this.loop = loop;
this.end = end;
state = State.Ended;
}
public void Magick(Ped ped)
{
if (state == State.Ended)
{
PlayStart(ped);
return;
}
if (state == State.Starting)
{
if (!IsAnimationPlaying(ped, start))
{
state = State.Looping;
PlayLoop(ped);
}
}
}
protected void PlayStart(Ped ped)
{
ped.Task.PlayAnimation(
start.dict,
start.name,
8f,
-1,
AnimationFlags.None
);
state = State.Starting;
}
protected void PlayLoop(Ped ped)
{
ped.Task.PlayAnimation(
loop.dict,
loop.name,
50f,
-1,
AnimationFlags.Loop
);
state = State.Looping;
}
protected void PlayEnd(Ped ped)
{
ped.Task.PlayAnimation(
end.dict,
end.name,
8f,
-1,
AnimationFlags.CancelableWithMovement
);
state = State.Ended;
}
public void RewindAndStop(Ped ped)
{
StopEntityAnim(ped.Handle, loop.name, loop.dict, 1f);
PlayEnd(ped);
}
protected bool IsAnimationPlaying(Ped ped, Animation anim)
{
return IsEntityPlayingAnim(ped.Handle, anim.dict, anim.name, 3);
}
}
}