Dave Boyle

Load filenames / titles for buttons from json streaming over network. button cli…

…cks load movies on server. timeout started
1 +fileFormatVersion: 2
2 +guid: e13b8882a7ba533438a133f2e7d91431
3 +timeCreated: 1465142182
4 +licenseType: Pro
5 +DefaultImporter:
6 + userData:
7 + assetBundleName:
8 + assetBundleVariant:
1 +[
2 + {
3 + "filename":"sample-1920x1024-divx.avi",
4 + "title":"test1"
5 + },
6 + {
7 + "filename":"lookUponThisAndDespair.mp4",
8 + "title":"test2"
9 + }
10 +]
...\ No newline at end of file ...\ No newline at end of file
1 +fileFormatVersion: 2
2 +guid: c27447788d27c3e46a51457c3c946143
3 +timeCreated: 1465142182
4 +licenseType: Pro
5 +DefaultImporter:
6 + userData:
7 + assetBundleName:
8 + assetBundleVariant:
No preview for this file type
1 +fileFormatVersion: 2
2 +guid: 2a6be515630c81a4b988e90741a7f6de
3 +timeCreated: 1465145480
4 +licenseType: Pro
5 +NativeFormatImporter:
6 + userData:
7 + assetBundleName:
8 + assetBundleVariant:
1 +using UnityEngine;
2 +using System.Collections;
3 +
4 +public class AppManager : Singleton<AppManager>
5 +{
6 + public AVProWindowsMediaMovie movieScript;
7 + public Canvas serverCanvas;
8 + public CanvasGroup inactiveCanvas;
9 + public float appTimeout;
10 +
11 + void Start ()
12 + {
13 + inactiveCanvas.alpha = 1;
14 + StartCoroutine(AppTimeout());
15 + }
16 +
17 + private bool _videoPlaying = false;
18 +
19 + private IEnumerator AppTimeout()
20 + {
21 + while(true)
22 + {
23 + float timeout = 0;
24 + bool didTimeout = false;
25 +
26 + while (!_videoPlaying)
27 + {
28 + timeout += Time.deltaTime;
29 + print(timeout);
30 +
31 + if (timeout >= appTimeout && ! didTimeout)
32 + {
33 + didTimeout = true;
34 + print("timeout");
35 + }
36 +
37 + yield return null;
38 + }
39 +
40 + yield return null;
41 + }
42 + }
43 +
44 + public void DestroyServerCanvas()
45 + {
46 + Destroy(serverCanvas.gameObject);
47 + }
48 +
49 + private Coroutine movieCoroutine;
50 +
51 + public void LoadMovie(string filename)
52 + {
53 + movieScript.UnloadMovie();
54 +
55 + movieScript._filename = filename;
56 + movieScript.LoadMovie(true);
57 +
58 + TweenCanvasGroup(inactiveCanvas, 0, 1);
59 +
60 + if (movieCoroutine != null)
61 + StopCoroutine(movieCoroutine);
62 +
63 + movieCoroutine = StartCoroutine(MoviePlaying());
64 + }
65 +
66 + private IEnumerator MoviePlaying()
67 + {
68 + _videoPlaying = true;
69 + while (movieScript.MovieInstance.IsPlaying)
70 + yield return null;
71 +
72 + _videoPlaying = false;
73 + }
74 +
75 + public void TweenCanvasGroup(CanvasGroup group, float alpha, float time)
76 + {
77 + TweenCanvasGroup(group, alpha, time, null);
78 + }
79 +
80 + public void TweenCanvasGroup(CanvasGroup group, float alpha, float time, System.Action onComplete)
81 + {
82 + Hashtable hash = new Hashtable()
83 + {
84 + { "from", group.alpha },
85 + { "to", alpha },
86 + { "time", time },
87 + { "onupdate", (System.Action<object>)(x => group.alpha = (float) x) }
88 + };
89 +
90 + if (onComplete != null)
91 + hash.Add("oncomplete", (System.Action<object>)(x => onComplete()));
92 +
93 + iTween.ValueTo(group.gameObject, hash);
94 + }
95 +}
1 -using UnityEngine;
2 -using System.Collections;
3 -
4 -public class MovieLoader : Singleton<MovieLoader>
5 -{
6 - public AVProWindowsMediaMovie movieScript;
7 -
8 - void Start () {
9 -
10 - }
11 -
12 - void Update ()
13 - {
14 - if (Input.GetKeyDown(KeyCode.Space))
15 - LoadMovie("sample-1920x1024-divx.avi");
16 - }
17 -
18 - public void LoadMovie(string filename)
19 - {
20 - movieScript._filename = filename;
21 - movieScript.LoadMovie(true);
22 - }
23 -}
1 +using UnityEngine;
2 +using System.Collections;
3 +
4 +public class MovieNode : MonoBehaviour {
5 +
6 + // Use this for initialization
7 + void Start () {
8 +
9 + }
10 +
11 + // Update is called once per frame
12 + void Update () {
13 +
14 + }
15 +}
1 +fileFormatVersion: 2
2 +guid: 17be018bbf1e14648965ed4257813488
3 +timeCreated: 1465141228
4 +licenseType: Pro
5 +MonoImporter:
6 + serializedVersion: 2
7 + defaultReferences: []
8 + executionOrder: 0
9 + icon: {instanceID: 0}
10 + userData:
11 + assetBundleName:
12 + assetBundleVariant:
1 +using UnityEngine;
2 +using System.Collections;
3 +using UnityEngine.UI;
4 +
5 +public class MoviePlayNode : MonoBehaviour
6 +{
7 + [SerializeField]
8 + private Text _textNode;
9 + private string _filename;
10 + private NetworkUser _netNode;
11 +
12 + public void Initialize(string title, string filename, NetworkUser parent)
13 + {
14 + _textNode.text = title;
15 + _filename = filename;
16 + _netNode = parent;
17 + }
18 +
19 + public void PlayMovie()
20 + {
21 + _netNode.CmdLoadVideo(_filename);
22 + }
23 +}
1 +fileFormatVersion: 2
2 +guid: 08da2dd2f9ee0ff45982c789efc1477c
3 +timeCreated: 1465145461
4 +licenseType: Pro
5 +MonoImporter:
6 + serializedVersion: 2
7 + defaultReferences: []
8 + executionOrder: 0
9 + icon: {instanceID: 0}
10 + userData:
11 + assetBundleName:
12 + assetBundleVariant:
1 using UnityEngine; 1 using UnityEngine;
2 using System.Collections; 2 using System.Collections;
3 +using System.Collections.Generic;
4 +using System.IO;
3 using UnityEngine.Networking; 5 using UnityEngine.Networking;
4 6
5 public class NetworkUser : NetworkBehaviour 7 public class NetworkUser : NetworkBehaviour
6 { 8 {
7 - void Start () { 9 + public Transform buttonParent;
10 + public MoviePlayNode movieButtonNode;
8 11
12 + void Start()
13 + {
14 + if (!isServer)
15 + {
16 + AppManager.Instance.DestroyServerCanvas();
17 + StartCoroutine(WaitForFiles());
18 + }
19 + else
20 + {
21 + string path = Application.streamingAssetsPath + "/videoSettings.json";
22 + if (!File.Exists(path))
23 + {
24 + Debug.LogError("NetworkUser Error: No videoSettings.json file found");
25 + return;
26 + }
27 + string json = File.ReadAllText(path);
28 + RpcGetFiles(json);
29 + }
30 + }
31 +
32 + public List<Dictionary<string, string>> _files;
33 +
34 + private IEnumerator WaitForFiles()
35 + {
36 + while (_files == null)
37 + yield return null;
38 +
39 + foreach(var dict in _files)
40 + {
41 + MoviePlayNode mpn = Instantiate<MoviePlayNode>(movieButtonNode);
42 + mpn.Initialize(dict["title"], dict["filename"], this);
43 + mpn.transform.SetParent(buttonParent);
44 + mpn.transform.localPosition = Vector3.zero;
45 + mpn.transform.localScale = Vector3.one;
46 + }
47 + // Do things
48 + }
49 +
50 + [ClientRpc]
51 + private void RpcGetFiles(string json)
52 + {
53 + var tempList = (IList)MiniJSON.Json.Deserialize(json);
54 +
55 + _files = new List<Dictionary<string, string>>();
56 +
57 + foreach (IDictionary dict in tempList)
58 + {
59 + var thisDict = new Dictionary<string, string>();
60 + foreach(DictionaryEntry de in dict)
61 + thisDict.Add(de.Key.ToString(), de.Value.ToString());
62 +
63 + _files.Add(thisDict);
64 + }
9 } 65 }
10 66
11 void Update () 67 void Update ()
12 { 68 {
13 - if (Input.GetKeyDown(KeyCode.Q)) 69 + if (Input.GetKeyDown(KeyCode.Alpha1))
14 - CmdLoadVideo("sample-1920x1024-divx.avi"); 70 + {
71 + var thisDict = _files[0];
72 + CmdLoadVideo(thisDict["filename"]);
73 + }
74 +
75 + if (Input.GetKeyDown(KeyCode.Alpha2))
76 + {
77 + var thisDict = _files[1];
78 + CmdLoadVideo(thisDict["filename"]);
79 + }
15 } 80 }
16 81
17 [Command] 82 [Command]
18 - private void CmdLoadVideo(string file) 83 + public void CmdLoadVideo(string file)
19 { 84 {
20 - MovieLoader.Instance.LoadMovie(file); 85 + AppManager.Instance.LoadMovie(file);
21 } 86 }
22 } 87 }
......
1 +fileFormatVersion: 2
2 +guid: ac9625a3e3a3b6940b20ab48f4ae3f74
3 +folderAsset: yes
4 +timeCreated: 1465142193
5 +licenseType: Pro
6 +DefaultImporter:
7 + userData:
8 + assetBundleName:
9 + assetBundleVariant:
1 +fileFormatVersion: 2
2 +guid: 42b9c08300f92b1409548cb10d273537
3 +timeCreated: 1465142182
4 +licenseType: Pro
5 +MonoImporter:
6 + serializedVersion: 2
7 + defaultReferences: []
8 + executionOrder: 0
9 + icon: {instanceID: 0}
10 + userData:
11 + assetBundleName:
12 + assetBundleVariant:
1 -m_EditorVersion: 5.3.4f1 1 +m_EditorVersion: 5.3.2f1
2 m_StandardAssetsVersion: 0 2 m_StandardAssetsVersion: 0
......