-
Notifications
You must be signed in to change notification settings - Fork 3
/
ParameterAnimFile.js
108 lines (90 loc) · 1.79 KB
/
ParameterAnimFile.js
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
#pragma strict
class ParameterAnimation
{
var duration = 1.0;
var looping = false;
var tweening = "linear";
var playOnAwake = false;
var delay = 0.0;
var debug = false;
private var passed:float;
private var state:String;
function ParameterAnimation()
{
state = "idle";
}
function GetLinearFraction() : float
{
var x = (Mathf.Max(0.0, passed-delay) / duration);
if( looping )
{
return x % 1.0;
}
else
{
return Mathf.Clamp( x, 0.0, 1.0 );
}
}
function SetLinearFraction(value:float)
{
passed = Mathf.Clamp(value, 0.0, 1.0)*duration + delay;
}
function GetFraction() : float
{
var t = GetLinearFraction();
if( tweening == "sincycle" )
{
// Map [0,1] to a full sin-cycle, mapped within [0,1]
// So 0->0, and 1->0, but 0.5->1.0
var rads = (1.0-t)*(-Mathf.PI/2.0) + t*(3.0*Mathf.PI/2.0);
var rv = Mathf.Sin(rads)*0.5 + 0.5;
return rv;
}
// TODO other tweeners here
else
{
return t;
}
}
function Play()
{
passed = 0.0;
state = "playing";
}
function IsPlaying() : boolean
{
return state == "playing";
}
function Stop()
{
passed = 0.0;
state = "idle";
}
function Pause()
{
state = "idle";
}
function Unpause()
{
state = "playing";
}
function Awake()
{
passed = 0.0;
if( playOnAwake )
{
Play();
}
}
function Update ()
{
if( state == "playing" )
{
passed += Time.deltaTime;
if( (passed-delay) > duration && !looping )
{
Pause();
}
}
}
}