// End game scenario : Cancel everything and go to the position public void CancelAndLeave(Vector3 startPos) { _navMeshAgent.SetDestination(startPos); destination = DestinationType.START; m_currentIncident = null; EndMeal(); }
// Start a random incident private void StartIncident() { // Reset Malus/Bonus timeToIncidentModifier = 0; int rand = UnityEngine.Random.Range(0, GameManager.instance.incidentIdToConfig.Keys.Count); int count = 0; m_waiting_timer = 0; foreach (KeyValuePair <uint, IncidentConfig> pair in GameManager.instance.incidentIdToConfig) { if (rand == count) { m_currentIncident = pair.Value; m_isEating = false; _childCanvas.EnableFeedback("Incident/incident_" + m_currentIncident.name.ToLower(), false, true); AudioClip incidentClip = m_IncidentsSFX[UnityEngine.Random.Range(0, m_IncidentsSFX.Count)]; m_AudioSourceSFX.clip = incidentClip; m_AudioSourceSFX.Play(); Debug.Log("Start new incident : " + m_currentIncident.name); break; } count++; } }
public static IncidentConfig ParseIncident(JSON json) { IncidentConfig config = new IncidentConfig( json.ToUInt(ID_CRC), json.ToString(ID), json.ToString(NAME) ); return(config); }
// Solve an incident with a kid // If he has vegetable to eat, he starts to eat again public bool SolveIncident(uint responseId) { bool result = false; ResponseConfig response = GameManager.instance.responseIdToConfig[responseId]; Debug.Log("Solve incident with: " + response.name); if (m_currentIncident != null) { UnityEngine.Assertions.Assert.IsTrue(response.incidentIdToResult.ContainsKey(m_currentIncident.id), "Can't find result for response " + response.name + " and " + m_currentIncident.name); result = response.incidentIdToResult[m_currentIncident.id]; if (result == false) { Debug.Log("Wrong response to incident: " + response.name); Debug.Log("malus " + response.time); // If Malus is more or equal to timeToIncident, we start a new incident if (m_currentVegetable.timeToIncident - response.time <= 0) { StartIncident(); _playerManager.UpdateScore(response.points, false); return(false); } else { timeToIncidentModifier = -response.time; } } else { Debug.Log("bonus " + response.time); timeToIncidentModifier = response.time; } _childCanvas.DisableFeedback(); _playerManager.UpdateScore(response.points, result); } m_currentIncident = null; if (m_currentVegetable != null) { m_isEating = true; m_elapsedTime = 0f; m_Slider_Foreground.color = _playerManager.playerColor; _childCanvas.EnableSlider(true); _childCanvas.EnableFeedback("Food/food_" + m_currentVegetable.name.ToLower(), true, true); } return(result); }
public static Dictionary <uint, IncidentConfig> ParseIncidents(JSON json) { Dictionary <uint, IncidentConfig> incidents = new Dictionary <uint, IncidentConfig>(); List <JSON> incidentConfigJSONs = json.ToJSONList(ROOT); int incidentCount = incidentConfigJSONs.Count; for (int i = 0; i < incidentCount; ++i) { IncidentConfig incidentConfig = ParseIncident(incidentConfigJSONs[i]); incidents.Add(incidentConfig.id, incidentConfig); } return(incidents); }