From d668718f124fd4efcbaa599fdf1bd37ad6fcf282 Mon Sep 17 00:00:00 2001 From: Ciakon Date: Tue, 12 Mar 2024 14:42:25 +0100 Subject: [PATCH] Added function that finds all possible dishes from ingredients --- Assets/Scenes/Noahs kælder.unity | 52 ++++++++++++++-------- Assets/Scripts/Cooking.cs | 75 +++++++++++++++++++++++++------- Assets/Scripts/Dish.cs | 1 + Assets/Scripts/Ingredient.cs | 3 -- 4 files changed, 94 insertions(+), 37 deletions(-) diff --git a/Assets/Scenes/Noahs kælder.unity b/Assets/Scenes/Noahs kælder.unity index e12d5b3..7bb0a01 100644 --- a/Assets/Scenes/Noahs kælder.unity +++ b/Assets/Scenes/Noahs kælder.unity @@ -257,6 +257,7 @@ MonoBehaviour: IngredientIn: - {fileID: 1790468147} - {fileID: 1714471222} + NutritionalValue: 0 --- !u!212 &143107366 SpriteRenderer: m_ObjectHideFlags: 0 @@ -380,7 +381,7 @@ BoxCollider2D: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} oldSize: {x: 0.64, y: 0.64} - newSize: {x: 1, y: 1} + newSize: {x: 0.64, y: 0.64} adaptiveTilingThreshold: 0.5 drawMode: 0 adaptiveTiling: 0 @@ -404,6 +405,7 @@ MonoBehaviour: IngredientIn: - {fileID: 460072661} - {fileID: 1525651426} + NutritionalValue: 0 --- !u!212 &389679694 SpriteRenderer: m_ObjectHideFlags: 0 @@ -450,7 +452,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 0.64, y: 0.64} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -491,6 +493,7 @@ MonoBehaviour: - {fileID: 1274549341} - {fileID: 1420342329} - {fileID: 885031692} + NutritionalValue: 0 --- !u!212 &460072663 SpriteRenderer: m_ObjectHideFlags: 0 @@ -537,7 +540,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 0.64, y: 0.64} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -617,7 +620,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 0 + m_SortingOrder: 1 m_Sprite: {fileID: 21300000, guid: d5d8b548c18b7ef47985238815778a0a, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 @@ -638,7 +641,7 @@ Transform: m_GameObject: {fileID: 537514707} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 2.04, y: -2.51, z: 0} m_LocalScale: {x: 2, y: 2, z: 2} m_ConstrainProportionsScale: 0 m_Children: [] @@ -660,6 +663,7 @@ MonoBehaviour: IngredientIn: - {fileID: 867381650} - {fileID: 1714471222} + NutritionalValue: 0 --- !u!61 &537514711 BoxCollider2D: m_ObjectHideFlags: 0 @@ -739,6 +743,7 @@ MonoBehaviour: - {fileID: 1001436608} - {fileID: 1274549341} - {fileID: 1659394507} + NutritionalValue: 0 --- !u!212 &578240411 SpriteRenderer: m_ObjectHideFlags: 0 @@ -785,7 +790,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 0.64, y: 0.64} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -997,6 +1002,7 @@ MonoBehaviour: m_EditorClassIdentifier: RequiredIngredients: - {fileID: 537514707} + NutritionalValue: 0 --- !u!1 &885031692 GameObject: m_ObjectHideFlags: 0 @@ -1025,7 +1031,7 @@ Transform: m_GameObject: {fileID: 885031692} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 2, y: 0, z: 0} + m_LocalPosition: {x: 3.06, y: -2.09, z: 0} m_LocalScale: {x: 2, y: 2, z: 2} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1091,6 +1097,7 @@ MonoBehaviour: transform: {fileID: 885031693} IngredientIn: - {fileID: 460072661} + NutritionalValue: 0 --- !u!212 &885031696 SpriteRenderer: m_ObjectHideFlags: 0 @@ -1238,6 +1245,7 @@ MonoBehaviour: IngredientIn: - {fileID: 1790468147} - {fileID: 578240409} + NutritionalValue: 0 --- !u!212 &1001436612 SpriteRenderer: m_ObjectHideFlags: 0 @@ -1347,7 +1355,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 0 + m_SortingOrder: -1 m_Sprite: {fileID: 21300000, guid: a28e0f4904f55524ea2137416707b61b, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 @@ -1368,7 +1376,7 @@ Transform: m_GameObject: {fileID: 1147379266} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 1.1} m_LocalScale: {x: 1.7, y: 1.7, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1445,7 +1453,7 @@ BoxCollider2D: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} oldSize: {x: 0.64, y: 0.64} - newSize: {x: 1, y: 1} + newSize: {x: 0.64, y: 0.64} adaptiveTilingThreshold: 0.5 drawMode: 0 adaptiveTiling: 0 @@ -1471,6 +1479,7 @@ MonoBehaviour: - {fileID: 460072661} - {fileID: 578240409} - {fileID: 1525651426} + NutritionalValue: 0 --- !u!212 &1274549345 SpriteRenderer: m_ObjectHideFlags: 0 @@ -1517,7 +1526,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 0.64, y: 0.64} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -1654,6 +1663,7 @@ MonoBehaviour: transform: {fileID: 1420342330} IngredientIn: - {fileID: 460072661} + NutritionalValue: 0 --- !u!212 &1420342333 SpriteRenderer: m_ObjectHideFlags: 0 @@ -1811,7 +1821,7 @@ SpriteRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 0 + m_SortingOrder: -1 m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 @@ -1821,7 +1831,7 @@ SpriteRenderer: m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 - m_MaskInteraction: 0 + m_MaskInteraction: 2 m_SpriteSortPoint: 0 --- !u!4 &1517788315 Transform: @@ -1832,7 +1842,7 @@ Transform: m_GameObject: {fileID: 1517788312} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.19, y: 3.03, z: -1} + m_LocalPosition: {x: -0.19, y: 3.03, z: 1} m_LocalScale: {x: 4.0825, y: 3.375, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1926,6 +1936,7 @@ MonoBehaviour: - {fileID: 1659394507} - {fileID: 1274549341} - {fileID: 389679690} + NutritionalValue: 0 --- !u!212 &1525651429 SpriteRenderer: m_ObjectHideFlags: 0 @@ -1972,7 +1983,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 0.64, y: 0.64} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -2049,7 +2060,7 @@ BoxCollider2D: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} oldSize: {x: 0.64, y: 0.64} - newSize: {x: 1, y: 1} + newSize: {x: 0.64, y: 0.64} adaptiveTilingThreshold: 0.5 drawMode: 0 adaptiveTiling: 0 @@ -2073,6 +2084,7 @@ MonoBehaviour: IngredientIn: - {fileID: 578240409} - {fileID: 1525651426} + NutritionalValue: 0 --- !u!212 &1659394511 SpriteRenderer: m_ObjectHideFlags: 0 @@ -2119,7 +2131,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 0.64, y: 0.64} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -2158,6 +2170,7 @@ MonoBehaviour: RequiredIngredients: - {fileID: 143107362} - {fileID: 537514707} + NutritionalValue: 0 --- !u!212 &1714471224 SpriteRenderer: m_ObjectHideFlags: 0 @@ -2204,7 +2217,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 0.64, y: 0.64} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -2274,6 +2287,7 @@ MonoBehaviour: - {fileID: 143107362} - {fileID: 1274549341} - {fileID: 1001436608} + NutritionalValue: 0 --- !u!212 &1790468150 SpriteRenderer: m_ObjectHideFlags: 0 @@ -2320,7 +2334,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 0.64, y: 0.64} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 diff --git a/Assets/Scripts/Cooking.cs b/Assets/Scripts/Cooking.cs index 3fe7b3f..90abb21 100644 --- a/Assets/Scripts/Cooking.cs +++ b/Assets/Scripts/Cooking.cs @@ -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().NutritionalValue); - } + // Debug.Log(ingredient.name); + // Debug.Log(ingredient.GetComponent().NutritionalValue); + // } - } + // } + void CreateDish() { + List Ingredients = GetIngredients(); + + List AllDishes = new List (); + + // Find all dishes ingredients can make + + foreach (GameObject Ingredient in Ingredients) { + List Dishes = Ingredient.GetComponent().IngredientIn; + + foreach (GameObject Dish in Dishes) { + AllDishes.Add(Dish); + } + } + + List PossibleDishes = new List (); + + // Find the dishes, where all ingredients exist + + foreach (GameObject Dish in AllDishes) { + List RequiredIngredients = Dish.GetComponent().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 currentCollisions = new List (); private void OnTriggerEnter2D(Collider2D other) { currentCollisions.Add (other.gameObject); - CheckDishes(); + CreateDish(); } private void OnTriggerExit2D(Collider2D other) { currentCollisions.Remove (other.gameObject); } - - - void Update() - { - GetIngredients(); - } - List GetIngredients() { return currentCollisions; } + // void Update() + // { + // GetIngredients(); + // } + + + + } diff --git a/Assets/Scripts/Dish.cs b/Assets/Scripts/Dish.cs index b2f4675..a1dba51 100644 --- a/Assets/Scripts/Dish.cs +++ b/Assets/Scripts/Dish.cs @@ -5,6 +5,7 @@ using UnityEngine; public class Dish : MonoBehaviour { public List RequiredIngredients; + public int NutritionalValue; // Start is called before the first frame update diff --git a/Assets/Scripts/Ingredient.cs b/Assets/Scripts/Ingredient.cs index f500919..2ea459e 100644 --- a/Assets/Scripts/Ingredient.cs +++ b/Assets/Scripts/Ingredient.cs @@ -33,9 +33,6 @@ public class Ingredient : MonoBehaviour void OnMouseUp() { if (isMoving) - - - isMoving = false; else isMoving = true;