Added function that finds all possible dishes from ingredients
This commit is contained in:
@@ -4,37 +4,82 @@ using UnityEngine;
|
||||
|
||||
public class Cooking : MonoBehaviour
|
||||
{
|
||||
void CheckDishes()
|
||||
{
|
||||
foreach (GameObject ingredient in currentCollisions) {
|
||||
// void CheckDishes()
|
||||
// {
|
||||
// foreach (GameObject ingredient in currentCollisions) {
|
||||
|
||||
Debug.Log(ingredient.name);
|
||||
Debug.Log(ingredient.GetComponent<Ingredient>().NutritionalValue);
|
||||
}
|
||||
// Debug.Log(ingredient.name);
|
||||
// Debug.Log(ingredient.GetComponent<Ingredient>().NutritionalValue);
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
void CreateDish() {
|
||||
List <GameObject> Ingredients = GetIngredients();
|
||||
|
||||
List <GameObject> AllDishes = new List <GameObject>();
|
||||
|
||||
// Find all dishes ingredients can make
|
||||
|
||||
foreach (GameObject Ingredient in Ingredients) {
|
||||
List <GameObject> Dishes = Ingredient.GetComponent<Ingredient>().IngredientIn;
|
||||
|
||||
foreach (GameObject Dish in Dishes) {
|
||||
AllDishes.Add(Dish);
|
||||
}
|
||||
}
|
||||
|
||||
List <GameObject> PossibleDishes = new List <GameObject>();
|
||||
|
||||
// Find the dishes, where all ingredients exist
|
||||
|
||||
foreach (GameObject Dish in AllDishes) {
|
||||
List <GameObject> RequiredIngredients = Dish.GetComponent<Dish>().RequiredIngredients;
|
||||
|
||||
int NumberOfIngredients = RequiredIngredients.Count;
|
||||
int IngredientsFulfilled = 0;
|
||||
|
||||
foreach (GameObject Ingredient in Ingredients) {
|
||||
|
||||
if (RequiredIngredients.Contains(Ingredient)) {
|
||||
IngredientsFulfilled++;
|
||||
}
|
||||
}
|
||||
|
||||
if (IngredientsFulfilled == NumberOfIngredients) {
|
||||
PossibleDishes.Add(Dish);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (GameObject Dish in PossibleDishes) {
|
||||
Debug.Log(Dish);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Keep track of ingredients going on and off the cooker.
|
||||
List <GameObject> currentCollisions = new List <GameObject> ();
|
||||
private void OnTriggerEnter2D(Collider2D other) {
|
||||
currentCollisions.Add (other.gameObject);
|
||||
CheckDishes();
|
||||
CreateDish();
|
||||
}
|
||||
private void OnTriggerExit2D(Collider2D other) {
|
||||
currentCollisions.Remove (other.gameObject);
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
GetIngredients();
|
||||
}
|
||||
|
||||
List <GameObject> GetIngredients()
|
||||
{
|
||||
return currentCollisions;
|
||||
}
|
||||
|
||||
|
||||
// void Update()
|
||||
// {
|
||||
// GetIngredients();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using UnityEngine;
|
||||
public class Dish : MonoBehaviour
|
||||
{
|
||||
public List <GameObject> RequiredIngredients;
|
||||
public int NutritionalValue;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
||||
@@ -33,9 +33,6 @@ public class Ingredient : MonoBehaviour
|
||||
void OnMouseUp()
|
||||
{
|
||||
if (isMoving)
|
||||
|
||||
|
||||
|
||||
isMoving = false;
|
||||
else
|
||||
isMoving = true;
|
||||
|
||||
Reference in New Issue
Block a user