NetworkUser.cs
2.44 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
96
97
98
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine.Networking;
public class NetworkUser : NetworkBehaviour
{
public Transform buttonParent;
public MoviePlayNode movieButtonNode;
void Start()
{
if (!isServer)
{
AppManager.Instance.DestroyServerCanvas();
StartCoroutine(WaitForFiles());
}
else
{
AppManager.Instance.Initialize();
string path = Application.streamingAssetsPath + "/videoSettings.json";
if (!File.Exists(path))
{
Debug.LogError("NetworkUser Error: No videoSettings.json file found");
return;
}
string json = File.ReadAllText(path);
RpcGetFiles(json);
}
}
public List<Dictionary<string, string>> _files;
private IEnumerator WaitForFiles()
{
while (_files == null)
yield return null;
foreach(var dict in _files)
{
MoviePlayNode mpn = Instantiate<MoviePlayNode>(movieButtonNode);
mpn.Initialize(dict["title"], dict["filename"], this);
mpn.transform.SetParent(buttonParent);
mpn.transform.localPosition = Vector3.zero;
mpn.transform.localScale = Vector3.one;
}
// Do things
}
[ClientRpc]
private void RpcGetFiles(string json)
{
var tempList = (IList)MiniJSON.Json.Deserialize(json);
_files = new List<Dictionary<string, string>>();
foreach (IDictionary dict in tempList)
{
var thisDict = new Dictionary<string, string>();
foreach(DictionaryEntry de in dict)
thisDict.Add(de.Key.ToString(), de.Value.ToString());
_files.Add(thisDict);
}
}
void Update ()
{
if (Input.touchCount > 0)
CmdResetTimer();
if (Input.GetKeyDown(KeyCode.Alpha1))
{
var thisDict = _files[0];
CmdLoadVideo(thisDict["filename"]);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
var thisDict = _files[1];
CmdLoadVideo(thisDict["filename"]);
}
}
[Command]
private void CmdResetTimer()
{
AppManager.Instance.ResetTimer();
}
[Command]
public void CmdLoadVideo(string file)
{
AppManager.Instance.LoadMovie(file);
}
}