File tree Expand file tree Collapse file tree 2 files changed +27
-17
lines changed Expand file tree Collapse file tree 2 files changed +27
-17
lines changed Original file line number Diff line number Diff line change 1
- using System . Threading . Tasks ;
1
+ using System . Collections ;
2
2
using UnityEngine ;
3
3
4
4
namespace UnityCore {
@@ -32,25 +32,37 @@ private void OnEnable() {
32
32
/// <summary>
33
33
/// Call this to turn the page on or off by setting the control '_on'
34
34
/// </summary>
35
- public async Task < bool > Animate ( bool _on ) {
35
+ public void Animate ( bool _on ) {
36
36
if ( useAnimation ) {
37
37
m_Animator . SetBool ( "on" , _on ) ;
38
-
39
- // wait for animation to finish
40
- isAnimating = true ;
41
- while ( m_Animator . GetCurrentAnimatorStateInfo ( 0 ) . normalizedTime < 1 ) {
42
- await Task . Delay ( 50 ) ;
43
- }
44
- isAnimating = false ;
38
+
39
+ StopCoroutine ( "AwaitAnimation" ) ;
40
+ StartCoroutine ( "AwaitAnimation" , _on ) ;
45
41
46
42
Log ( "Page [" + type + "] finished transitioning to " + ( _on ? "<color=#0f0>on</color>." : "<color=#f00>off</color>." ) ) ;
47
43
}
48
-
49
- return true ;
50
44
}
51
45
#endregion
52
46
53
47
#region Private Functions
48
+ private IEnumerator AwaitAnimation ( bool _on ) {
49
+ string _targetState = _on ? "On" : "Off" ;
50
+ isAnimating = true ;
51
+
52
+ while ( ! m_Animator . GetCurrentAnimatorStateInfo ( 0 ) . IsName ( _targetState ) ) {
53
+ yield return null ;
54
+ }
55
+ while ( m_Animator . GetCurrentAnimatorStateInfo ( 0 ) . normalizedTime < 1 ) {
56
+ yield return null ;
57
+ }
58
+
59
+ isAnimating = false ;
60
+
61
+ if ( ! _on ) {
62
+ gameObject . SetActive ( false ) ;
63
+ }
64
+ }
65
+
54
66
private void CheckAnimatorIntegrity ( ) {
55
67
if ( useAnimation ) {
56
68
// try to get animator
Original file line number Diff line number Diff line change 1
1
using System . Collections . Generic ;
2
2
using System . Collections ;
3
- using System . Threading . Tasks ;
4
3
using UnityEngine ;
5
4
6
5
namespace UnityCore {
@@ -42,26 +41,25 @@ private void Update() {
42
41
#endregion
43
42
44
43
#region Public Functions
45
- public async void TurnPageOn ( PageType _type ) {
44
+ public void TurnPageOn ( PageType _type ) {
46
45
if ( ! PageExists ( _type ) ) {
47
46
LogWarning ( "You are trying to turn a page on [" + _type + "] that has not been registered." ) ;
48
47
return ;
49
48
}
50
49
51
50
Page _page = GetPage ( _type ) ;
52
51
_page . gameObject . SetActive ( true ) ;
53
- await _page . Animate ( true ) ;
52
+ _page . Animate ( true ) ;
54
53
}
55
54
56
- public async void TurnPageOff ( PageType _type ) {
55
+ public void TurnPageOff ( PageType _type ) {
57
56
if ( ! PageExists ( _type ) ) {
58
57
LogWarning ( "You are trying to turn a page off [" + _type + "] that has not been registered." ) ;
59
58
return ;
60
59
}
61
60
62
61
Page _page = GetPage ( _type ) ;
63
- await _page . Animate ( false ) ;
64
- //_page.gameObject.SetActive(false);
62
+ _page . Animate ( false ) ;
65
63
}
66
64
#endregion
67
65
You can’t perform that action at this time.
0 commit comments