SandwichManager.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //================================================================================
  2. //
  3. //================================================================================
  4. using UnityEngine;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. //================================================================================
  8. //
  9. //================================================================================
  10. namespace ReaderRabbit
  11. {
  12. //================================================================================
  13. //
  14. //================================================================================
  15. public class SandwichManager : MonoBehaviour
  16. {
  17. //================================================================================
  18. //
  19. //================================================================================
  20. private const int MIN_NUMBER_OF_INGREDIENTS = 3;
  21. [SerializeField] private int m_MaxNumberOfIngredientsPerType = 15;
  22. [SerializeField] private List<SandwichIngredientsColumn> m_Columns;
  23. private IngredientDescriptor m_SelectedIngredient;
  24. private Dictionary<string, int> m_NumberOfIngredientsPerType;
  25. //================================================================================
  26. //
  27. //================================================================================
  28. void Awake()
  29. {
  30. m_NumberOfIngredientsPerType = new Dictionary<string, int>();
  31. }
  32. //================================================================================
  33. //
  34. //================================================================================
  35. public bool ProcessIngredientAddition(IngredientDescriptor ingredient, Vector2 position)
  36. {
  37. if (!m_NumberOfIngredientsPerType.ContainsKey(ingredient.IngredientName))
  38. {
  39. m_NumberOfIngredientsPerType.Add(ingredient.IngredientName, 1);
  40. }
  41. if (m_NumberOfIngredientsPerType[ingredient.IngredientName] <= m_MaxNumberOfIngredientsPerType)
  42. {
  43. foreach (SandwichIngredientsColumn column in m_Columns)
  44. {
  45. if (column.GetComponent<Collider2D>().bounds.Contains(position))
  46. {
  47. if (column.AddIngredient(ingredient.gameObject))
  48. {
  49. m_NumberOfIngredientsPerType[ingredient.IngredientName]++;
  50. return true;
  51. }
  52. }
  53. }
  54. }
  55. else
  56. {
  57. // TODO: Play max number of ingredient type feedback
  58. }
  59. return false;
  60. }
  61. //================================================================================
  62. //
  63. //================================================================================
  64. public void ResetNumberOfIngredientsPerType()
  65. {
  66. m_NumberOfIngredientsPerType.Clear();
  67. }
  68. //================================================================================
  69. //
  70. //================================================================================
  71. public bool HasEnoughIngredients()
  72. {
  73. return (m_NumberOfIngredientsPerType.Count >= MIN_NUMBER_OF_INGREDIENTS);
  74. }
  75. //================================================================================
  76. //
  77. //================================================================================
  78. public float GetMaximumIngredientsHeight()
  79. {
  80. float maximumHeight = 0;
  81. foreach (SandwichIngredientsColumn column in m_Columns)
  82. {
  83. if (column.GetIngredientsHeight() > maximumHeight)
  84. {
  85. maximumHeight = column.GetIngredientsHeight();
  86. }
  87. }
  88. return maximumHeight;
  89. }
  90. //================================================================================
  91. //
  92. //================================================================================
  93. public void Reset()
  94. {
  95. m_NumberOfIngredientsPerType.Clear();
  96. foreach (SandwichIngredientsColumn column in m_Columns)
  97. {
  98. column.Reset();
  99. }
  100. }
  101. //================================================================================
  102. //
  103. //================================================================================
  104. public int GetNumberOfDifferendIngredients()
  105. {
  106. return m_NumberOfIngredientsPerType.Keys.Count;
  107. }
  108. //================================================================================
  109. //
  110. //================================================================================
  111. public bool IsIngredientMaxed(IngredientDescriptor ingredient)
  112. {
  113. int count = 0;
  114. m_NumberOfIngredientsPerType.TryGetValue(ingredient.IngredientName, out count);
  115. return count >= m_MaxNumberOfIngredientsPerType;
  116. }
  117. } // public class SandwichManager : MonoBehaviour
  118. } // namespace ReaderRabbit