//================================================================================ // //================================================================================ using UnityEngine; using System.Collections; using System.Collections.Generic; //================================================================================ // //================================================================================ namespace ReaderRabbit { //================================================================================ // //================================================================================ public class SandwichManager : MonoBehaviour { //================================================================================ // //================================================================================ private const int MIN_NUMBER_OF_INGREDIENTS = 3; [SerializeField] private int m_MaxNumberOfIngredientsPerType = 15; [SerializeField] private List m_Columns; private IngredientDescriptor m_SelectedIngredient; private Dictionary m_NumberOfIngredientsPerType; //================================================================================ // //================================================================================ void Awake() { m_NumberOfIngredientsPerType = new Dictionary(); } //================================================================================ // //================================================================================ public bool ProcessIngredientAddition(IngredientDescriptor ingredient, Vector2 position) { if (!m_NumberOfIngredientsPerType.ContainsKey(ingredient.IngredientName)) { m_NumberOfIngredientsPerType.Add(ingredient.IngredientName, 1); } if (m_NumberOfIngredientsPerType[ingredient.IngredientName] <= m_MaxNumberOfIngredientsPerType) { foreach (SandwichIngredientsColumn column in m_Columns) { if (column.GetComponent().bounds.Contains(position)) { if (column.AddIngredient(ingredient.gameObject)) { m_NumberOfIngredientsPerType[ingredient.IngredientName]++; return true; } } } } else { // TODO: Play max number of ingredient type feedback } return false; } //================================================================================ // //================================================================================ public void ResetNumberOfIngredientsPerType() { m_NumberOfIngredientsPerType.Clear(); } //================================================================================ // //================================================================================ public bool HasEnoughIngredients() { return (m_NumberOfIngredientsPerType.Count >= MIN_NUMBER_OF_INGREDIENTS); } //================================================================================ // //================================================================================ public float GetMaximumIngredientsHeight() { float maximumHeight = 0; foreach (SandwichIngredientsColumn column in m_Columns) { if (column.GetIngredientsHeight() > maximumHeight) { maximumHeight = column.GetIngredientsHeight(); } } return maximumHeight; } //================================================================================ // //================================================================================ public void Reset() { m_NumberOfIngredientsPerType.Clear(); foreach (SandwichIngredientsColumn column in m_Columns) { column.Reset(); } } //================================================================================ // //================================================================================ public int GetNumberOfDifferendIngredients() { return m_NumberOfIngredientsPerType.Keys.Count; } //================================================================================ // //================================================================================ public bool IsIngredientMaxed(IngredientDescriptor ingredient) { int count = 0; m_NumberOfIngredientsPerType.TryGetValue(ingredient.IngredientName, out count); return count >= m_MaxNumberOfIngredientsPerType; } } // public class SandwichManager : MonoBehaviour } // namespace ReaderRabbit