Tanoda
LoadRemoteData.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using JetBrains.Annotations;
7using Newtonsoft.Json;
8using UnityEngine;
9
10public class LoadRemoteData : MonoBehaviour
11{
12 // Start is called before the first frame update
13 void Start()
14 {
15 StartCoroutine(LoadPos());
16 }
17
18 IEnumerator LoadPos()
19 {
20 yield return new WaitForSeconds(0.5f);
21 var downloadedJsonString = "";
22#if UNITY_EDITOR
23
24 downloadedJsonString = File.ReadAllText(@"C:\Users\UnityTeam\Downloads\level.json");
25 Debug.Log(downloadedJsonString);
26#endif
27
28 var remoteJson = JsonConvert.DeserializeObject<SceneNode>(downloadedJsonString);
29 var goList = GameObject.FindObjectsOfType<JSONPositioner>();
30 foreach (var jsonPositioner in goList)
31 {
32 try
33 {
34 jsonPositioner.PassData(FindHash(remoteJson, jsonPositioner.Hash));
35 }
36 catch (Exception)
37 {
38 // ignored
39 }
40 }
41 yield return null;
42 }
43
44 [CanBeNull]
45 SceneNode FindHash(SceneNode root, string hash)
46 {
47 if (hash == root.hash) return root;
48 SceneNode retval = null;
49 foreach (var rootChild in root.children)
50 {
51 retval = FindHash(rootChild, hash);
52 if (retval != null)
53 {
54 return retval;
55 }
56 }
57 return retval;
58 }
59
60 // Update is called once per frame
61 void Update()
62 {
63
64 }
65}
66
67[Serializable]
68public class SceneNode
69{
70 public string name;
71 public string hash;
72 public int stage;
73 public int holderIndex;
74 public Vector3 finalpos;
75 public Vector3 finalrot;
76 public Vector3 finalfwd;
77 public Vector3 finalrgt;
78 public Vector3 final_up;
79 public float tolp;
80 public float tolr;
82 public Vector3 localPos;
83 public List<SceneNode> children;
84}
85
86[Serializable]
87public class JSONTransform
88{
89 public Vector3 position;
90 public Quaternion rotation;
91 public Vector3 scale;
92}
93
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void PassData(SceneNode json)
Quaternion rotation
Vector3 position
Vector3 finalpos
Vector3 finalrgt
Vector3 finalfwd
JSONTransform transform
string hash
Vector3 finalrot
List< SceneNode > children
Vector3 localPos
string name
Vector3 final_up