public void LoadQuestResources() { questFilesById = new Dictionary <string, QuestJSON>(); TextAsset[] questFileAssets = Resources.LoadAll <TextAsset>(questFilePath); // Debug.Log("Number of Quest Assets: " + questFileAssets.Length); foreach (TextAsset questAsset in questFileAssets) { // Debug.Log("Quest text asset: " + questAsset.text); QuestJSON quest = QuestJSON.CreateFromJSON(questAsset.text); if (quest != null) { // Debug.Log("Quest: " + quest.GetFieldValues()); questFilesById.Add(quest.questId, quest); } } Debug.Log("Loaded: " + questFilesById.Keys.Count + " Quests"); questLineFilesById = new Dictionary <string, QuestLineJSON>(); TextAsset[] questLineAssets = Resources.LoadAll <TextAsset>(questLineFilePath); foreach (TextAsset questLineAsset in questLineAssets) { QuestLineJSON questLine = QuestLineJSON.CreateFromJSON(questLineAsset.text); if (questLine != null) { // Debug.Log("Quest Line: " + questLine.GetFieldValues()); questLineFilesById.Add(questLine.questLineId, questLine); } } Debug.Log("Loaded: " + questLineFilesById.Keys.Count + " Quest Lines"); }
public static QuestJSON CreateFromJSON(string questStr) { JSONNode questNode = JSON.Parse(questStr); QuestJSON questJSON = JsonUtility.FromJson <QuestJSON>(questStr); questJSON.rewards = JsonUtility.FromJson <QuestRewardsJSON>(questNode["rewards"].ToString()); return(questJSON); }
private void Form1_Load(object sender, EventArgs e) { // Load the Quests.json DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { savePath = Path.GetDirectoryName(openFileDialog1.FileName); string jsonString = File.ReadAllText(openFileDialog1.FileName); string filename = openFileDialog1.FileName; string [] paths = filename.Split('\\'); string file = paths[paths.Length - 1]; if (file != "Quests.json") { MessageBox.Show("File opened is not Quests.json"); Application.Exit(); } else { _tempQuestJson = JsonSerializer.Deserialize <QuestJSON>(jsonString); // Events comboBoxQuestList.SelectedIndexChanged += OnComboBoxQuestListSelectedIndexChanged; // Load titles on the combo box comboBoxQuestList.SelectedIndex = 0; foreach (QuestObject qo in _tempQuestJson.quests) { comboBoxQuestList.Items.Add(qo.id); } } } else { MessageBox.Show("No file opened."); Application.Exit(); } }
private void ReloadQuests() { MessageBox.Show("Reloading Quests.json"); string jsonString = File.ReadAllText(openFileDialog1.FileName); // Reset _tempQuestJson.Reset(); comboBoxQuestList.Items.Clear(); comboBoxQuestList.Items.Add("New"); _tempQuestJson = JsonSerializer.Deserialize <QuestJSON>(jsonString); // Load titles on the combo box comboBoxQuestList.SelectedIndex = 0; foreach (QuestObject qo in _tempQuestJson.quests) { comboBoxQuestList.Items.Add(qo.id); } }