private void JSONToData(string gameDataFileName, ref RecipeSpecJSON rs) { string filePath = Path.Combine(Application.streamingAssetsPath, gameDataFileName); // Path.Combine combines strings into a file path at Assets/StreamingAssets if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); // Read the json from the file into a string rs = JsonUtility.FromJson <RecipeSpecJSON>(dataAsJson); // Pass the json to JsonUtility, and tell it to create a GameData object from it } else { Debug.LogError("Cannot load recipe data!"); } }
public List <Recipe> getRecipesJSON(string filename)//, ref Dictionary<string, Submodule> smd) { Debug.Log("importing recipes from " + filename); RecipeSpecJSON rsj = new RecipeSpecJSON(); JSONToData(filename, ref rsj); List <Recipe> rs = new List <Recipe>(); if (rsj.recipe_count != rsj.recipes.Count) { Debug.Log("Number of recipes received does not match recipes manifest..."); } for (int i = 0; i < rsj.recipes.Count; i++) { RecipeJSON rj = rsj.recipes[i]; Recipe r = new Recipe(rj.id, rj.name, rj.ingredients, rj.connections); rs.Add(r); //Debug.Log(rj.ingredients[0].type); //Debug.Log(rj.connections[0].conn); //Submodule sm = new Submodule(smj.name, smj.part_count, smj.part_refs, smj.part_names, smj.part_values, smj.part_positions, smj.part_rotations, smj.connections, smj.attributes); //smd.Add(sm.name, sm); } return(rs); }