123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- //================================================================================
- //
- //================================================================================
- 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<SandwichIngredientsColumn> m_Columns;
- private IngredientDescriptor m_SelectedIngredient;
- private Dictionary<string, int> m_NumberOfIngredientsPerType;
- //================================================================================
- //
- //================================================================================
- void Awake()
- {
- m_NumberOfIngredientsPerType = new Dictionary<string, int>();
- }
- //================================================================================
- //
- //================================================================================
- 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<Collider2D>().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
|