-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFadeCurtains.js
93 lines (79 loc) · 1.58 KB
/
FadeCurtains.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
#pragma strict
@script RequireComponent(Connectable)
public static var main:FadeCurtains = null;
var openCloseSecs = 1.0;
var alpha = new SlidingValue();
var startOpen = false;
private var state = "open";
function Awake()
{
Utils.Assert( main == null );
main = this;
if( startOpen )
{
alpha.Set(0.0);
state = "open";
}
else
{
alpha.Set(1.0);
state = "closed";
}
}
function Start()
{
}
function Open()
{
if( state == "closing" || state == "closed" )
{
alpha.SlideTo(0.0);
state = "opening";
GetComponent(Connectable).TriggerEvent("OnCurtainsOpening");
}
}
function Close()
{
if( state == "open" || state == "opening" )
{
alpha.SlideTo(1.0);
state = "closing";
GetComponent(Connectable).TriggerEvent("OnCurtainsClosing");
}
else if( state == "closed" )
{
// fire event immediately
GetComponent(Connectable).TriggerEvent("OnCurtainsClosed");
}
}
private function OnAlphaChanged()
{
var alphaComp = GetComponent(AlphaHierarchy);
Utils.Assert(alphaComp);
alphaComp.SetLocalAlpha( alpha.Get(), true );
}
function Update()
{
alpha.Update(Time.deltaTime);
if( state == "opening" )
{
if( alpha.Get() <= 0.0 )
{
state = "open";
GetComponent(Connectable).TriggerEvent("OnCurtainsOpened");
}
OnAlphaChanged();
}
else if( state == "closing" )
{
if( alpha.Get() >= 1.0 )
{
state = "closed";
GetComponent(Connectable).TriggerEvent("OnCurtainsClosed");
}
OnAlphaChanged();
}
else
{
}
}