示例#1
0
    void logAll()
    {
        RecipeDefinitions     allRecipes     = FoodData.Instance.GetAllRecipes;
        IngredientDefinitions allIngredients = FoodData.Instance.GetAllIngredients;

        Debug.Log("All Recipes:");

        /* Iterate through all recipes, printing their name */
        for (int i = 0; i < allRecipes.recipes.Length; i++)
        {
            Debug.Log(allRecipes.recipes[i].name + " is made with:");
            Debug.Log("-----");
            /* Iterate through all ingredients of current recipe, printing name */
            for (int j = 0; j < allRecipes.recipes[i].ingredients.Length; j++)
            {
                Debug.Log(allRecipes.recipes[i].ingredients[j].name);
            }
            Debug.Log("-----");
        }

        Debug.Log("All Ingredients:");

        for (int i = 0; i < allIngredients.ingredients.Length; i++)
        {
            Debug.Log(allIngredients.ingredients[i].name);
        }
    }
示例#2
0
    FoodData()
    {
        /* Read recipe data from JSON file */
        TextAsset recipeFile = (TextAsset)Resources.Load(recipesFileName, typeof(TextAsset));
        string    recipeJSON = recipeFile.ToString();

        /* Read ingredient data from JSON file */
        TextAsset ingredientFile = (TextAsset)Resources.Load(ingredientsFileName, typeof(TextAsset));
        string    ingredientJSON = ingredientFile.ToString();

        /* Parse recipe JSON data */
        allRecipes = JsonUtility.FromJson <RecipeDefinitions>(recipeJSON);

        /* Parse ingredient JSON data */
        allIngredients = JsonUtility.FromJson <IngredientDefinitions>(ingredientJSON);
    }