2 using System.Collections.Generic;
24 private GameObject widgetPrefab;
30 private GameObject success;
35 private GameObject webError;
40 private GameObject serverCommunication;
44 private bool test =
false;
46 private GameObject testSceneObj;
48 private string fileName =
"test.json";
49 #endregion //TEST_FIELDS 51 #region PRIVATE_MEMBER_VARIABLES 53 private List<InfluxReader> widgets;
54 private List<InfluxReader> tempWidgets;
56 private bool isRunning =
false;
57 #endregion //PRIVATE_MEMBER_VARIABLES 59 #region UNITY_MONOBEHAVIOUR_METHODS 69 Destroy(this.gameObject);
71 tempWidgets =
new List<InfluxReader>();
72 widgets =
new List<InfluxReader>();
78 #endregion //UNITY_MONOBEHAVIOUR_METHODS 80 #region PUBLIC_METHODS 89 DBScene scene = Serialize.Utility.CreateFromJSON(json);
90 BuildScene(scene, origin);
91 StartCoroutine(SetUpWidgets());
92 Debug.Log(
"Finish init");
122 tempWidgets.Add(toAdd);
139 id =
id.Substring(0, 24);
140 UnityWebRequest www = Receiver.GetFromId(
id);
141 Debug.Log(
"Created Web Request object for: " + www.url);
143 www.downloadHandler =
new DownloadHandlerBuffer();
144 serverCommunication.SetActive(
true);
146 yield
return www.SendWebRequest();
148 Debug.Log(
"Response Code: " + www.responseCode);
149 if (www.isNetworkError || www.isHttpError)
151 Debug.Log(www.error);
152 webError.SetActive(
true);
153 serverCommunication.SetActive(
false);
158 string results = www.downloadHandler.text;
159 Debug.Log(
"Printing results...");
161 yield
return www.downloadHandler.text;
162 success.SetActive(
true);
163 serverCommunication.SetActive(
false);
181 #endregion //PUBLIC_METHODS 183 #region PRIVATE_METHODS 184 private void BuildScene(DBScene conf, GameObject sceneObj)
195 foreach (DBWidget wid
in conf.Widgets)
197 CreateWidgets(wid, sceneObj);
208 private void CreateWidgets(DBWidget wid, GameObject sceneObj)
210 GameObject newWidget = Instantiate(widgetPrefab);
211 newWidget.transform.parent = sceneObj.transform;
212 newWidget.transform.localPosition = wid.Position;
214 r.
SetDBVals(wid.Measure, wid.Building, wid.Room);
223 private IEnumerator SetUpWidgets()
226 while (!AllWidgetsSetup())
241 if (tempWidgets.Count != 0)
243 widgets.AddRange(tempWidgets);
255 private bool AllWidgetsSetup()
271 string filePath = Path.Combine(Application.streamingAssetsPath, fileName);
273 if (File.Exists(filePath))
279 #endregion //PRIVATE_METHODS
Singleton object for handling scene loading and widget creation
void InitializeScene(string json, GameObject origin)
Deserializes a scene configuration and builds it on the origin location
void Setup(DBScene sceneToBuild)
Given a deserialized scene configuration, set all Influx server values from config ...
void AddWidget< T >(IList< T > toAdd)
Adds widgets to list of active widgets
IEnumerator GetText(string id)
Starts get request to fetch config for a given ID
static JSONBuilder instance
void UpdateWidgets()
Updates all widgets that are set to update
Object for storing scene configuration settings - should be parent to widgets