//load the state of all quests from the player prefs private void load() { bool alteredOnLoad = false; //load quests states from PlayerPrefs string json = SecurePlayerPrefs.GetString(jsonKey); if (!string.IsNullOrEmpty(json)) { JsonUtility.FromJsonOverwrite(json, questBook); } //search through the catalog and add quests if they are new foreach (QuestDefinition questDefinition in catalog) { if (!IsQuestInQuestbook(questDefinition)) { C_QuestState questState = new C_QuestState(); questState.quest = questDefinition; questState.questKey = questDefinition.name; questBook.quests.Add(questState); alteredOnLoad = true; } } //clear the temporary list for active quests questBook.activeQuests.Clear(); //regenerate link to the scriptable object and search/add active quests to the temporary list foreach (C_QuestState qs in questBook.quests) { QuestDefinition quest = GetQuestFromCatalogByKey(qs.questKey); if (quest != null) { qs.quest = quest; qs.loadedFromCatalog = true; //ifthe quest is active, also add it to the active list if (qs.activeState == E_QuestActiveState.active) { questBook.activeQuests.Add(qs); } } else { qs.loadedFromCatalog = false; } } loaded = true; if (alteredOnLoad == true) { save(); } }
void createQuestFinishedPopup(C_QuestState questState) { if (questFullfillmentPopup.popupParent != null && questFullfillmentPopup.popupPrefab != null) { GameObject popup = (GameObject)Instantiate(questFullfillmentPopup.popupPrefab); popup.transform.SetParent(questFullfillmentPopup.popupParent.transform, false); Quest_UIItem questUiItem = popup.GetComponent <Quest_UIItem>(); if (questUiItem != null) { questUiItem.SetQuestState(questState); } else { Debug.LogWarning("The popup for the fullfillment of quest '" + questState.questKey + "' couldn't be displayed because the script 'Quest_UIItem' is not attached in the popup prefab."); } } }