| | | 1 | | /* |
| | | 2 | | * |
| | | 3 | | * Code by: |
| | | 4 | | * Dimitrios Vlachos |
| | | 5 | | * djv1@student.london.ac.uk |
| | | 6 | | * dimitri.j.vlachos@gmail.com |
| | | 7 | | * |
| | | 8 | | * Adapted from our Games Dev FSM lecture |
| | | 9 | | * |
| | | 10 | | */ |
| | | 11 | | |
| | | 12 | | using System.Collections; |
| | | 13 | | using System.Collections.Generic; |
| | | 14 | | using TMPro; |
| | | 15 | | using UnityEngine; |
| | | 16 | | |
| | | 17 | | public class RecipeManager : MonoBehaviour |
| | | 18 | | { |
| | | 19 | | #region Variables |
| | | 20 | | public RecipeBaseState state; |
| | | 21 | | public GameObject anchor; |
| | | 22 | | |
| | | 23 | | [Header("States")] |
| | 2 | 24 | | public RecipeState1 state1 = new(); |
| | 2 | 25 | | public RecipeState2 state2 = new(); |
| | | 26 | | |
| | | 27 | | [Header("UI")] |
| | | 28 | | public TextMeshProUGUI objective; |
| | | 29 | | public TextMeshProUGUI status; |
| | | 30 | | |
| | | 31 | | [Header("Objective information")] |
| | | 32 | | public GameObject pot; |
| | | 33 | | public PotBehaviour potBehaviour; |
| | | 34 | | public int numberOfPotatos; |
| | | 35 | | public int numberOfCarrots; |
| | | 36 | | public int water; |
| | | 37 | | #endregion |
| | | 38 | | |
| | | 39 | | // This makes a singleton Recipe Manager object |
| | | 40 | | #region Singleton declaration |
| | 2 | 41 | | public static RecipeManager Recipe { get; private set; } |
| | | 42 | | |
| | | 43 | | private void Awake() |
| | 1 | 44 | | { |
| | | 45 | | // Singletone protection stuff |
| | 1 | 46 | | if (Recipe != null && Recipe != this) |
| | 0 | 47 | | { |
| | 0 | 48 | | Destroy(this); |
| | 0 | 49 | | } |
| | | 50 | | else |
| | 1 | 51 | | { |
| | 1 | 52 | | Recipe = this; |
| | 1 | 53 | | } |
| | 1 | 54 | | } |
| | | 55 | | #endregion |
| | | 56 | | |
| | | 57 | | // Start is called before the first frame update |
| | | 58 | | void Start() |
| | 1 | 59 | | { |
| | 1 | 60 | | objective.text = string.Empty; |
| | 1 | 61 | | status.text = string.Empty; |
| | | 62 | | |
| | 1 | 63 | | numberOfPotatos = 0; |
| | 1 | 64 | | numberOfCarrots = 0; |
| | 1 | 65 | | water = 0; |
| | | 66 | | |
| | 1 | 67 | | potBehaviour = pot.GetComponent<PotBehaviour>(); |
| | | 68 | | |
| | 1 | 69 | | MoveToState(state1); |
| | 1 | 70 | | } |
| | | 71 | | |
| | | 72 | | // Update is called once per frame |
| | | 73 | | void Update() |
| | 1682 | 74 | | { |
| | 1682 | 75 | | state.Update(); |
| | 1682 | 76 | | transform.position = anchor.transform.position; |
| | 1682 | 77 | | } |
| | | 78 | | |
| | | 79 | | public void MoveToState(RecipeBaseState state) |
| | 1 | 80 | | { |
| | 1 | 81 | | Debug.Log("Entering state: " + state); |
| | 1 | 82 | | this.state = state; |
| | 1 | 83 | | state.EnterState(this); |
| | 1 | 84 | | } |
| | | 85 | | } |