void SaveNewDataToFileFromDatabase(DataSnapshot snapshot) { ContactPointCollection contactPoints = new ContactPointCollection(); JsonUtility.FromJsonOverwrite(snapshot.GetRawJsonValue(), contactPoints); TriviaSaveLoadSystem.SaveContactPoints(contactPoints); }
public void CheckDatabaseVersion() { #if !UNITY_EDITOR EnableLoadingIndicator(); string currentDatabaseVersion = PlayerPrefs.GetString("database_version"); FirebaseDatabase.DefaultInstance .GetReference("database_version") .GetValueAsync().ContinueWith(task => { if (task.IsCompleted) { DataSnapshot snapshot = task.Result; string verNumberString = snapshot.GetRawJsonValue(); if (verNumberString != currentDatabaseVersion) { TriviaSaveLoadSystem.DeleteData(); PlayerPrefs.SetString("database_version", verNumberString); //TODO: Implement a function that checks current selected language, possible to do with the localization manager or playerprefabs. DownloadWithNewLanguage(); } else { myPointData = TriviaSaveLoadSystem.LoadContactPoints(); if (myPointData != null) { //trivia up to date SpawnUpToDatePanel(); } } } }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); #endif }
IEnumerator Start() { triviaCanvas.EnableLoadIndicator(); contactPoints = TriviaSaveLoadSystem.LoadContactPoints(); if (contactPoints == null) { //unity error triviaCanvas.DisableLoadIndicator(); questions = SetDummyRoundData(); SuffleQuestionOrder(ref questions); currentQuestion = questions[currentQuestionNumber]; EnableQuestionCanvas(); SetScoreText(); questionCanvas.setNewQuestionUI(currentQuestion); } else { int questionAmount = maxQuestions; triviaCanvas.DisableLoadIndicator(); //id that is inside the contact point;contactpoint.identifier if (PlayerPrefs.GetInt("TriviaAllRandom", 0) == 1) { //reset all random state PlayerPrefs.SetInt("TriviaAllRandom", 0); AllRandomAllQuestions(); questionAmount = maxRandomQs; } else { currentContactPointIndex = SelectContactPointIndex(PlayerPrefs.GetInt("CurrentLocationIdentifier", 0)); questions = contactPoints.points[currentContactPointIndex].questions; } DisplayCurrentQuestionAndEnableCanvas(questionAmount); } yield return(true); }
// Activate pop-up and set the correct texts public void PushLocBtn(int locationIndex) { Debug.Log(locationIndex); if (lastLocation != null) { Debug.Log("LAST LOCATION: " + lastLocation.name); } Debug.Log("LOCINDEX LOCATION: " + locations[locationIndex].name); cameraMovementScript.CanMove = false; //load info from a file contactPoints = TriviaSaveLoadSystem.LoadContactPoints(); ContactPoint currentLocationData = null; if (contactPoints == null) { Debug.LogWarning("You propably run in editor. Contact points are null"); } else { for (int i = 0; i < contactPoints.points.Length; i++) { if (contactPoints.points[i].identifier.ToString() == locations[locationIndex].identifier) { currentLocationData = contactPoints.points[i]; break; } } } bool contactPointValidation = (contactPoints != null && locationIndex <= contactPoints.points.Length && currentLocationData != null); string locationNameFromFile = (contactPointValidation) ? currentLocationData.name : locations[locationIndex].name; string locationDescriptionFromFile = (contactPointValidation) ? currentLocationData.description : locations[locationIndex].description; // Open pop-up and show correct info infoPanelObj.GetComponent <DisableScript>().enabled = false; infoPanelObj.SetActive(true); gpsBtnScript.HideOrShowButtons(true); infoAnim.SetBool("ShowPanel", true); locationTitleText.text = locationNameFromFile; locationDescText.text = locationDescriptionFromFile; // Set listener for play button playBtn.onClick.AddListener(delegate { PushPlayBtn(locBtns[locationIndex].transform.name); }); triviaBtn.onClick.AddListener(delegate { PushTriviaBtn(locationIndex); }); if (canOpenMenu && lastLocation != null && lastLocation.name == locations[locationIndex].name) { triviaInactiveText.SetActive(false); triviaActiveText.SetActive(true); // Example classify = (input >= 0) ? "nonnegative" : "negative"; string localizedLocation = (LocalizationManager.Instance != null) ? LocalizationManager.Instance.GetLocalizedValue("location_proximity_in") : "Trivia"; triviaBtn.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = localizedLocation; //popupLocImg.color = Color.green; triviaBtn.GetComponent <Image>().color = activeColor; } else { triviaInactiveText.SetActive(true); triviaActiveText.SetActive(false); // Example classify = (input >= 0) ? "nonnegative" : "negative"; string localizedLocation = (LocalizationManager.Instance != null) ? LocalizationManager.Instance.GetLocalizedValue("location_proximity_off") : " Et ole alueella"; triviaBtn.transform.GetChild(1).GetComponent <TextMeshProUGUI>().text = localizedLocation; //popupLocImg.color = Color.red; triviaBtn.GetComponent <Image>().color = inactiveColor; } }