123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- //================================================================================
- //
- //================================================================================
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using SimpleJSON;
- //================================================================================
- //
- //================================================================================
- namespace ReaderRabbit
- {
- //================================================================================
- //
- //================================================================================
- public class IngredientSelectionMachine : MonoBehaviour
- {
- //================================================================================
- //
- //================================================================================
- private const int DEFAULT_INGREDIENT_INDEX = 28;
- [SerializeField] private List<IngredientDescriptor> m_Ingredients;
- //[SerializeField] private RRButton m_LeftArrow;
- //[SerializeField] private RRButton m_RightArrow;
- [SerializeField] private GameObject m_IngredientsAreaRedBorder;
- [SerializeField] private GameObject m_IngredientsAreaYellowBorder;
- [SerializeField] private GameObject m_IngredientsAreaGreenBorder;
- private int m_CurrentSelectedIngredientIndex;
- private IngredientDescriptor m_CurrentPurchasedIngredient;
- private SceneSillySandwichShop m_Scene;
- //================================================================================
- //
- //================================================================================
- void Start()
- {
- //Tomato index: it's the default item
- m_CurrentSelectedIngredientIndex = DEFAULT_INGREDIENT_INDEX;
- m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(true);
-
- UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex]);
- m_Scene = GameObject.Find("SceneCode").GetComponent<SceneSillySandwichShop>();
- foreach (IngredientDescriptor go in m_Ingredients)
- {
- KishiTechUnity.ScreenResolution.ScreenResolutionManager.Instance().ForceUpdateGameObject(go.gameObject);
- }
- }
- //================================================================================
- //
- //================================================================================
- public void MoveRight()
- {
- m_Scene.PlayChangedYourMindSpeech(m_Ingredients[m_CurrentSelectedIngredientIndex]);
- m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(false);
- m_CurrentSelectedIngredientIndex++;
-
- if (m_CurrentSelectedIngredientIndex >= m_Ingredients.Count)
- {
- m_CurrentSelectedIngredientIndex = 0;
- }
- m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(true);
- UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex]);
-
- this.Owner.OnChangeIngredient();
- }
- //================================================================================
- //
- //================================================================================
- public void MoveLeft()
- {
- m_Scene.PlayChangedYourMindSpeech(m_Ingredients[m_CurrentSelectedIngredientIndex]);
- m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(false);
- m_CurrentSelectedIngredientIndex--;
-
- if (m_CurrentSelectedIngredientIndex < 0)
- {
- m_CurrentSelectedIngredientIndex = m_Ingredients.Count - 1;
- }
- m_Ingredients[m_CurrentSelectedIngredientIndex].gameObject.SetActive(true);
- UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex]);
-
- this.Owner.OnChangeIngredient();
- }
- //================================================================================
- //
- //================================================================================
- public void TriggerMinigameStart()
- {
- if (!m_Ingredients[m_CurrentSelectedIngredientIndex].Purchased)
- {
- UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex], true);
- this.Owner.TriggerMinigameStart(m_Ingredients[m_CurrentSelectedIngredientIndex]);
- }
- else
- {
- this.Owner.PlayIngredientName(m_Ingredients[m_CurrentSelectedIngredientIndex]);
- }
- }
- //================================================================================
- //
- //================================================================================
- public void SetupIngredientsDescriptions(JSONNode wordLists, int listSize)
- {
- foreach (IngredientDescriptor ingredient in m_Ingredients)
- {
- JSONNode wordList = wordLists["WordList_"+Random.Range(1, listSize)];
- ingredient.Setup(wordList["Set_"+Random.Range(1, 4)]);
- }
- }
- //================================================================================
- //
- //================================================================================
- public void UpdateIngredientsAreaBorder(IngredientDescriptor ingredient, bool selectedIngredient = false)
- {
- if (ingredient.Purchased)
- {
- m_IngredientsAreaGreenBorder.SetActive(true);
- m_IngredientsAreaRedBorder.SetActive(false);
- m_IngredientsAreaYellowBorder.SetActive(false);
- }
- else if (!selectedIngredient)
- {
- m_IngredientsAreaGreenBorder.SetActive(false);
- m_IngredientsAreaRedBorder.SetActive(true);
- m_IngredientsAreaYellowBorder.SetActive(false);
- }
- else if (selectedIngredient)
- {
- m_IngredientsAreaGreenBorder.SetActive(false);
- m_IngredientsAreaRedBorder.SetActive(false);
- m_IngredientsAreaYellowBorder.SetActive(true);
- }
- }
- //================================================================================
- //
- //================================================================================
- public IngredientDescriptor InstantiatePurchasedIngredient(IngredientDescriptor ingredientType)
- {
- m_CurrentPurchasedIngredient = ((GameObject)GameObject.Instantiate(ingredientType.gameObject)).GetComponent<IngredientDescriptor>();
- m_CurrentPurchasedIngredient.HideLabels();
- m_CurrentPurchasedIngredient.Purchased = true;
- return m_CurrentPurchasedIngredient;
- }
- //================================================================================
- //
- //================================================================================
- public void Reset()
- {
- UpdateIngredientsAreaBorder(m_Ingredients[m_CurrentSelectedIngredientIndex]);
- }
- //================================================================================
- //
- //================================================================================
- public SceneSillySandwichShop Owner
- {
- get; set;
- }
-
- } // public class IngredientSelectionMachine : MonoBehaviour
-
- } // namespace ReaderRabbit
|