private void LoadData() { string gmfFilePath = Path.Combine(Application.streamingAssetsPath, gmfFileName); print(gmfFilePath); if (File.Exists(gmfFilePath)) { string gmfAsJson = File.ReadAllText(gmfFilePath); jsondata = JsonUtility.FromJson <TJSONdata>(gmfAsJson); } else { Debug.LogError("Cannot load game data!"); } }
private void LoadMeshData() { /* * string filePath = Path.Combine(Application.streamingAssetsPath, meshDataFileName); * print(filePath); * * if (File.Exists(filePath)) * { * string meshAsJson = File.ReadAllText(filePath); * modelmesh = JsonUtility.FromJson<TModelMeshData>(meshAsJson); * * print("horizonts: " + modelmesh.horizonts.Length + " " + modelmesh.horizonts[0].name); * * } * else * { * Debug.LogError("Cannot load game data!"); * } */ string gmfFilePath = Path.Combine(Application.streamingAssetsPath, gmfFileName); print(gmfFilePath); if (File.Exists(gmfFilePath)) { string gmfAsJson = File.ReadAllText(gmfFilePath); jsondata = JsonUtility.FromJson <TJSONdata>(gmfAsJson); // string json; // json = JsonUtility.ToJson(jsondata); // print(json); print("bores (" + jsondata.gmfdata.data3d.bores.Length + "): " + jsondata.gmfdata.data3d.bores[0].name + ", ..."); print("horizonts (" + jsondata.gmfdata.data3d.mesh.horizonts.Length + "): " + jsondata.gmfdata.data3d.mesh.horizonts[0].name + ", ..."); } else { Debug.LogError("Cannot load game data!"); } float minx, maxx, miny, maxy, minz, maxz; float x, y, z; minx = miny = minz = 1000000000.0F; maxx = maxy = maxz = -minx; for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++) { THorizontData horz = jsondata.gmfdata.data3d.mesh.horizonts[h]; Vector3[] vertices; for (int j = 0; j < 3; j++) { vertices = horz.surfaceup.vertices; if (j == 1) { vertices = horz.surfacedn.vertices; } if (j == 2) { vertices = horz.surfacesd.vertices; } for (int i = 0; i < vertices.Length; i++) { x = vertices[i].x *= 0.02F; y = vertices[i].y *= 0.05F; z = vertices[i].z *= 0.02F; if (x > maxx) { maxx = x; } if (x < minx) { minx = x; } if (y != 0.0F && y > maxy) { maxy = y; } if (y != 0.0F && y < miny) { miny = y; } if (z > maxz) { maxz = z; } if (z < minz) { minz = z; } } } } print("box: " + minx + ", " + maxx + ", " + miny + ", " + maxy + ", " + minz + ", " + maxz); x = -(minx + maxx) * 0.5F; y = -miny; z = -(minz + maxz) * 0.5F; for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++) { THorizontData horz = jsondata.gmfdata.data3d.mesh.horizonts[h]; Vector3[] vertices; for (int j = 0; j < 3; j++) { vertices = horz.surfaceup.vertices; if (j == 1) { vertices = horz.surfacedn.vertices; } if (j == 2) { vertices = horz.surfacesd.vertices; } for (int i = 0; i < vertices.Length; i++) { vertices[i].x += x; if (vertices[i].y != 0.0F) { vertices[i].y += y; } vertices[i].z += z; } } } minx = miny = minz = 1000000000.0F; maxx = maxy = maxz = -minx; for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++) { THorizontData horz = jsondata.gmfdata.data3d.mesh.horizonts[h]; Vector3[] vertices; for (int j = 0; j < 3; j++) { vertices = horz.surfaceup.vertices; if (j == 1) { vertices = horz.surfacedn.vertices; } if (j == 2) { vertices = horz.surfacesd.vertices; } for (int i = 0; i < vertices.Length; i++) { x = vertices[i].x; y = vertices[i].y; z = vertices[i].z; if (x > maxx) { maxx = x; } if (x < minx) { minx = x; } if (y != 0.0F && y > maxy) { maxy = y; } if (y != 0.0F && y < miny) { miny = y; } if (z > maxz) { maxz = z; } if (z < minz) { minz = z; } } } } print("box: " + minx + ", " + maxx + ", " + miny + ", " + maxy + ", " + minz + ", " + maxz); }