11 protected Widget m_Widget;
12 protected int m_iState;
13 protected int m_iFormerState
14 protected float m_fFadeOutWaitTime;
15 protected float m_fFadeInSpeed;
16 protected float m_fFadeOutSpeed;
17 protected bool m_bForceVisible;
18 protected float m_fTimer;
19 protected bool m_bFadeOutSetVisibleFalse;
20 protected bool m_bAutoFadeOut;
23 const int STATE_FADE_IN = 0;
24 const int STATE_FADE_OUT_WAIT = 1;
25 const int STATE_FADE_OUT = 2;
26 const int STATE_FADING_DONE = 3;
29 ref ScriptInvoker<int, int> m_OnStateChanged;
32 void SCR_FadeInOutAnimator(Widget w,
float fadeInSpeed,
float fadeOutSpeed,
float fadeOutWaitTime,
bool fadeOutSetVisibleFalse =
false)
35 m_fFadeOutSpeed = fadeOutSpeed;
37 m_fFadeOutWaitTime = fadeOutWaitTime;
38 m_bFadeOutSetVisibleFalse = fadeOutSetVisibleFalse;
39 m_bAutoFadeOut =
true;
41 m_iState = STATE_FADE_OUT_WAIT;
42 m_bForceVisible =
false;
46 void Update(
float timeSlice)
50 case STATE_FADING_DONE:
52 if (m_bForceVisible && m_Widget.GetOpacity() < 1)
54 m_iState = STATE_FADE_IN;
56 m_OnStateChanged.Invoke(STATE_FADING_DONE, m_iState);
63 float opacity = Math.Clamp(m_Widget.GetOpacity() + timeSlice *
m_fFadeInSpeed, 0 ,1);
64 m_Widget.SetOpacity(opacity);
65 m_Widget.SetVisible(
true);
72 m_iState = STATE_FADE_OUT_WAIT;
74 m_OnStateChanged.Invoke(STATE_FADE_IN, m_iState);
78 m_iState = STATE_FADING_DONE;
80 m_OnStateChanged.Invoke(STATE_FADE_IN, m_iState);
86 case STATE_FADE_OUT_WAIT:
98 m_iState = STATE_FADE_OUT;
100 m_OnStateChanged.Invoke(STATE_FADE_OUT_WAIT, m_iState);
109 m_iState = STATE_FADE_IN;
110 if (m_OnStateChanged)
111 m_OnStateChanged.Invoke(STATE_FADE_OUT, m_iState);
115 float opacity = Math.Clamp(m_Widget.GetOpacity() - m_fFadeOutSpeed*timeSlice, 0, 1);
116 m_Widget.SetOpacity(opacity);
120 if (m_bFadeOutSetVisibleFalse)
121 m_Widget.SetVisible(
false);
123 m_iState = STATE_FADING_DONE;
124 if (m_OnStateChanged)
125 m_OnStateChanged.Invoke(STATE_FADE_OUT, m_iState);
133 void FadeIn(
bool fadeOut =
true)
135 m_bAutoFadeOut = fadeOut;
136 m_iFormerState = m_iState;
137 m_iState = STATE_FADE_IN;
138 if (m_OnStateChanged)
139 m_OnStateChanged.Invoke(m_iFormerState, m_iState);
145 m_iFormerState = m_iState;
146 m_iState = STATE_FADE_OUT;
147 if (m_OnStateChanged)
148 m_OnStateChanged.Invoke(m_iFormerState, m_iState);
152 void FadeOutInstantly()
154 m_Widget.SetOpacity(0);
155 m_iFormerState = m_iState;
156 m_iState = STATE_FADE_OUT;
157 if (m_OnStateChanged)
158 m_OnStateChanged.Invoke(m_iFormerState, m_iState);
163 void ForceVisible(
bool force)
165 m_bForceVisible = force;
179 return m_iState != STATE_FADING_DONE;
182 ScriptInvoker GetOnStateChanged()
184 if (!m_OnStateChanged)
185 m_OnStateChanged = ScriptInvoker();
186 return m_OnStateChanged;