Beispiel #1
0
    public void OnGUI()
    {
        if (quests.GetQuests().Count == 0)
        {
            quests = QuestFileManager.LoadFile();
        }

        if (GUILayout.Button("Add quest", GUILayout.MaxWidth(100)))
        {
            AddQuest addQuestEditor = (AddQuest)EditorWindow.GetWindow(typeof(AddQuest));
            addQuestEditor.setQuestTree(quests);
            addQuestEditor.Show();
        }
        if (GUILayout.Button("Reset quest", GUILayout.MaxWidth(100)))
        {
            foreach (Quest quest in quests.GetQuests())
            {
                QuestFileManager.DeleteQuest(quest);
            }
            quests.Empty();
        }

        EditorGUILayout.BeginScrollView(new Vector2(0, 0), true, true);
        if (quests.GetQuests().Count != 0)
        {
            foreach (Quest quest in quests.GetQuests())
            {
                if (GUILayout.Button(quest.QuestName, GUILayout.MaxWidth(100)))
                {
                    EditQuest editQuest = (EditQuest)EditorWindow.GetWindow(typeof(EditQuest));
                    editQuest.setQuestTree(quests);
                    editQuest.setQuest(quest);
                    editQuest.Show();
                }
            }
        }
        EditorGUILayout.EndScrollView();
    }
    public static void SaveFile(QuestTree data)
    {
        List <Quest> quests = data.GetQuests();

        if (!Directory.Exists(Application.dataPath + "/Quests/"))
        {
            Directory.CreateDirectory(Application.dataPath + "/Quests/");
        }
        foreach (Quest quest in quests)
        {
            string path = Application.dataPath + "/Quests/" + filename + "_" + quest.QuestName + ".json";
            File.Delete(path);
            StreamWriter writer = new StreamWriter(File.OpenWrite(path), System.Text.Encoding.UTF8);
            Debug.Log(QuestFileManager.serializeQuest(quest));
            writer.Write(QuestFileManager.serializeQuest(quest));
            writer.Close();
        }
    }