Load filenames / titles for buttons from json streaming over network. button cli…
…cks load movies on server. timeout started
Showing
26 changed files
with
286 additions
and
32 deletions
No preview for this file type
Assets/StreamingAssets/videoSettings.json
0 → 100644
Assets/_Nest/Prefabs/moviePlayNode.prefab
0 → 100644
No preview for this file type
No preview for this file type
No preview for this file type
Assets/_Nest/Scripts/AppManager.cs
0 → 100644
| 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 | +} |
Assets/_Nest/Scripts/MovieLoader.cs
deleted
100644 → 0
| 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 | -} |
Assets/_Nest/Scripts/MovieNode.cs
0 → 100644
Assets/_Nest/Scripts/MovieNode.cs.meta
0 → 100644
Assets/_Nest/Scripts/MoviePlayNode.cs
0 → 100644
| 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 | +} |
Assets/_Nest/Scripts/MoviePlayNode.cs.meta
0 → 100644
| 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; |
| 8 | - | 10 | + public MoviePlayNode movieButtonNode; |
| 9 | - } | 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 | + } | ||
| 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 | + { |
| 15 | - } | 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 | + } | ||
| 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 | } | ... | ... |
Assets/_Nest/Scripts/Utility.meta
0 → 100644
Assets/_Nest/Scripts/Utility/MiniJSON.cs
0 → 100644
This diff is collapsed.
Click to expand it.
No preview for this file type
No preview for this file type
-
Please register or sign in to post a comment