/// <summary> /// Called on Start. Loads the airport's flights from the data folder. /// </summary> public void LoadFlights() { string jsonPath = SplineReader.GetDataPath(m_airportCode) + "/manifest.json"; Debug.Log("jsonPath: " + jsonPath); string jsonText; #if UNITY_EDITOR if (!System.IO.File.Exists(jsonPath)) { Debug.Log("JSON doesn't exist: " + jsonPath); return; } jsonText = System.IO.File.ReadAllText(jsonPath); #elif UNITY_ANDROID WWW reader = new WWW(jsonPath); while (!reader.isDone) { } jsonText = reader.text; #endif Debug.Log("Loaded json..."); var rootNode = JSON.Parse(jsonText); int numListed = 0; foreach (KeyValuePair <string, JSONNode> entry in rootNode.AsObject) { numListed += 1; var flightInfo = entry.Value; Flight flight = null; bool hasFlight = m_cachedFlights.TryGetValue(entry.Key, out flight); if (!hasFlight) { string toAirp = flightInfo["to"].Value; string fromAirp = flightInfo["from"].Value; int startTimestamp = flightInfo["start"].AsInt; int endTimestamp = flightInfo["end"].AsInt; flight = new Flight(entry.Key, fromAirp, toAirp, startTimestamp, endTimestamp, transform, m_airportCode, m_flightPathMaterial); flight.gameObject.layer = this.gameObject.layer; if (!flight.didLoad) { Debug.Log("Error: Flight didn't load: " + entry.Key); } m_cachedFlights[entry.Key] = flight; } } Debug.Log("Loaded " + m_cachedFlights.Count + "/" + numListed + " flights"); }
/// <summary> /// Read spline data from binary format on disk /// </summary> private bool LoadData() { string pointsPath = SplineReader.GetDataPath(m_selectedAirportCode) + "/" + m_key + ".bin"; List <SVector3> sPositions = null; #if UNITY_EDITOR if (!File.Exists(pointsPath)) { Debug.Log("ERROR: Spline path doesnt exist: " + pointsPath); return(false); } try { using (Stream stream = File.Open(pointsPath, FileMode.Open)) { BinaryFormatter bin = new BinaryFormatter(); sPositions = (List <SVector3>)bin.Deserialize(stream); } } catch (Exception exc) { Debug.Log("Exception: " + exc.Message); return(false); } #elif UNITY_ANDROID try { WWW reader = new WWW(pointsPath); while (!reader.isDone) { } MemoryStream stream = new MemoryStream(reader.bytes); BinaryFormatter bin = new BinaryFormatter(); sPositions = (List <SVector3>)bin.Deserialize(stream); stream.Close(); } catch (Exception exc) { Debug.Log("Exception: " + exc.Message); return(false); } #endif m_vertexCount = sPositions.Count; m_splinePositions = new Vector3[m_vertexCount]; for (int j = 0; j < m_vertexCount; ++j) { int idx = j; m_splinePositions[j] = (Vector3)sPositions[idx]; } return(true); }