NetworkUser.cs
2.82 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine.Networking;
public class NetworkUser : NetworkBehaviour
{
public Transform buttonParent;
public GameObject canvas;
public List<MoviePlayNode> movieButtonNodes;
void Start()
{
if (!isServer)
{
StartCoroutine(WaitForFiles());
}
else
{
Destroy(canvas);
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 thisNode = null;
foreach(MoviePlayNode n in movieButtonNodes)
{
if (n.objTag == dict["tag"])
{
thisNode = n;
break;
}
}
if (thisNode == null)
{
Debug.LogError("There is no node with tag " + dict["tag"]);
continue;
}
//MoviePlayNode mpn = Instantiate<MoviePlayNode>(thisNode);
thisNode.Initialize(dict["filename"], this);
//mpn.transform.SetParent(buttonParent);
//mpn.transform.localPosition = Vector3.zero;
//mpn.transform.localScale = Vector3.one;
}
}
[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()
{
ServerCanvasManager.Instance.ResetTimer();
}
[Command]
public void CmdLoadVideo(string file)
{
ServerCanvasManager.Instance.LoadMovie(file);
}
}