IngredientSelectionMachine.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //================================================================================
  2. //
  3. //================================================================================
  4. using UnityEngine;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using SimpleJSON;
  8. //================================================================================
  9. //
  10. //================================================================================
  11. namespace ReaderRabbit
  12. {
  13. //================================================================================
  14. //
  15. //================================================================================
  16. public class IngredientSelectionMachine : MonoBehaviour
  17. {
  18. //================================================================================
  19. //
  20. //================================================================================
  21. private const int DEFAULT_INGREDIENT_INDEX = 28;
  22. [SerializeField] private List<IngredientDescriptor> m_Ingredients;
  23. //[SerializeField] private RRButton m_LeftArrow;
  24. //[SerializeField] private RRButton m_RightArrow;
  25. [SerializeField] private GameObject m_IngredientsAreaRedBorder;
  26. [SerializeField] private GameObject m_IngredientsAreaYellowBorder;
  27. [SerializeField] private GameObject m_IngredientsAreaGreenBorder;
  28. private int m_CurrentSelectedIngredientIndex;
  29. private IngredientDescriptor m_CurrentPurchasedIngredient;
  30. private SceneSillySandwichShop m_Scene;
  31. //================================================================================
  32. //
  33. //================================================================================
  34. void Start()
  35. {
  36. //Tomato index: it's the default item
  37. m_CurrentSelectedIngredientIndex = DEFAULT_INGREDIENT_INDEX;
  38. m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(true);
  39. UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex]);
  40. m_Scene = GameObject.Find("SceneCode").GetComponent<SceneSillySandwichShop>();
  41. foreach (IngredientDescriptor go in m_Ingredients)
  42. {
  43. KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(go.gameObject);
  44. }
  45. }
  46. //================================================================================
  47. //
  48. //================================================================================
  49. public void MoveRight()
  50. {
  51. m_Scene.PlayChangedYourMindSpeech(m_Ingredients[m_CurrentSelectedIngredientIndex]);
  52. m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(false);
  53. m_CurrentSelectedIngredientIndex++;
  54. if (m_CurrentSelectedIngredientIndex >= m_Ingredients.Count)
  55. {
  56. m_CurrentSelectedIngredientIndex = 0;
  57. }
  58. m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(true);
  59. UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex]);
  60. this.Owner.OnChangeIngredient();
  61. }
  62. //================================================================================
  63. //
  64. //================================================================================
  65. public void MoveLeft()
  66. {
  67. m_Scene.PlayChangedYourMindSpeech(m_Ingredients[m_CurrentSelectedIngredientIndex]);
  68. m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(false);
  69. m_CurrentSelectedIngredientIndex--;
  70. if (m_CurrentSelectedIngredientIndex < 0)
  71. {
  72. m_CurrentSelectedIngredientIndex = m_Ingredients.Count - 1;
  73. }
  74. m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(true);
  75. UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex]);
  76. this.Owner.OnChangeIngredient();
  77. }
  78. //================================================================================
  79. //
  80. //================================================================================
  81. public void TriggerMinigameStart()
  82. {
  83. if (!m_Ingredients[m_CurrentSelectedIngredientIndex].Purchased)
  84. {
  85. UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex], true);
  86. this.Owner.TriggerMinigameStart(m_Ingredients[m_CurrentSelectedIngredientIndex]);
  87. }
  88. else
  89. {
  90. this.Owner.PlayIngredientName(m_Ingredients[m_CurrentSelectedIngredientIndex]);
  91. }
  92. }
  93. //================================================================================
  94. //
  95. //================================================================================
  96. public void SetupIngredientsDescriptions(JSONNode wordLists, int listSize)
  97. {
  98. foreach (IngredientDescriptor ingredient in m_Ingredients)
  99. {
  100. JSONNode wordList = wordLists["WordList_"+Random.Range(1, listSize)];
  101. ingredient.Setup(wordList["Set_"+Random.Range(1, 4)]);
  102. }
  103. }
  104. //================================================================================
  105. //
  106. //================================================================================
  107. public void UpdateIngredientsAreaBorder(IngredientDescriptor ingredient, bool selectedIngredient = false)
  108. {
  109. if (ingredient.Purchased)
  110. {
  111. m_IngredientsAreaGreenBorder.SetActive(true);
  112. m_IngredientsAreaRedBorder.SetActive(false);
  113. m_IngredientsAreaYellowBorder.SetActive(false);
  114. }
  115. else if (!selectedIngredient)
  116. {
  117. m_IngredientsAreaGreenBorder.SetActive(false);
  118. m_IngredientsAreaRedBorder.SetActive(true);
  119. m_IngredientsAreaYellowBorder.SetActive(false);
  120. }
  121. else if (selectedIngredient)
  122. {
  123. m_IngredientsAreaGreenBorder.SetActive(false);
  124. m_IngredientsAreaRedBorder.SetActive(false);
  125. m_IngredientsAreaYellowBorder.SetActive(true);
  126. }
  127. }
  128. //================================================================================
  129. //
  130. //================================================================================
  131. public IngredientDescriptor InstantiatePurchasedIngredient(IngredientDescriptor ingredientType)
  132. {
  133. m_CurrentPurchasedIngredient = ((GameObject)GameObject.Instantiate(ingredientType.gameObject)).GetComponent<IngredientDescriptor>();
  134. m_CurrentPurchasedIngredient.HideLabels();
  135. m_CurrentPurchasedIngredient.Purchased = true;
  136. return m_CurrentPurchasedIngredient;
  137. }
  138. //================================================================================
  139. //
  140. //================================================================================
  141. public void Reset()
  142. {
  143. UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex]);
  144. }
  145. //================================================================================
  146. //
  147. //================================================================================
  148. public SceneSillySandwichShop Owner
  149. {
  150. get; set;
  151. }
  152. } // public class IngredientSelectionMachine : MonoBehaviour
  153. } // namespace ReaderRabbit