AppManager.cs
2.22 KB
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
using UnityEngine;
using System.Collections;
public class AppManager : Singleton<AppManager>
{
public AVProWindowsMediaMovie movieScript;
public Canvas serverCanvas;
public CanvasGroup inactiveCanvas;
public float appTimeout;
void Start ()
{
inactiveCanvas.alpha = 1;
StartCoroutine(AppTimeout());
}
private bool _videoPlaying = false;
private IEnumerator AppTimeout()
{
while(true)
{
float timeout = 0;
bool didTimeout = false;
while (!_videoPlaying)
{
timeout += Time.deltaTime;
print(timeout);
if (timeout >= appTimeout && ! didTimeout)
{
didTimeout = true;
print("timeout");
}
yield return null;
}
yield return null;
}
}
public void DestroyServerCanvas()
{
Destroy(serverCanvas.gameObject);
}
private Coroutine movieCoroutine;
public void LoadMovie(string filename)
{
movieScript.UnloadMovie();
movieScript._filename = filename;
movieScript.LoadMovie(true);
TweenCanvasGroup(inactiveCanvas, 0, 1);
if (movieCoroutine != null)
StopCoroutine(movieCoroutine);
movieCoroutine = StartCoroutine(MoviePlaying());
}
private IEnumerator MoviePlaying()
{
_videoPlaying = true;
while (movieScript.MovieInstance.IsPlaying)
yield return null;
_videoPlaying = false;
}
public void TweenCanvasGroup(CanvasGroup group, float alpha, float time)
{
TweenCanvasGroup(group, alpha, time, null);
}
public void TweenCanvasGroup(CanvasGroup group, float alpha, float time, System.Action onComplete)
{
Hashtable hash = new Hashtable()
{
{ "from", group.alpha },
{ "to", alpha },
{ "time", time },
{ "onupdate", (System.Action<object>)(x => group.alpha = (float) x) }
};
if (onComplete != null)
hash.Add("oncomplete", (System.Action<object>)(x => onComplete()));
iTween.ValueTo(group.gameObject, hash);
}
}