Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections.Generic;
- public class QuestManager : MonoBehaviour
- {
- public static QuestManager Instance;
- public List<Quest> allQuests = new List<Quest>(); // All available quests in the game
- public List<Quest> activeQuests = new List<Quest>();
- public List<Quest> completedQuests = new List<Quest>();
- private void Awake()
- {
- if (Instance == null)
- {
- Instance = this;
- DontDestroyOnLoad(gameObject);
- }
- else
- {
- Destroy(gameObject);
- }
- }
- public void AddActiveQuest(Quest quest)
- {
- activeQuests.Add(quest);
- }
- public void MarkQuestCompleted(Quest quest)
- {
- activeQuests.Remove(quest);
- completedQuests.Add(quest);
- }
- public QuestSaveData GetSaveData()
- {
- QuestSaveData data = new QuestSaveData();
- data.activeQuestIds = activeQuests.ConvertAll(q => q.questId);
- data.completedQuestIds = completedQuests.ConvertAll(q => q.questId);
- return data;
- }
- public void LoadSaveData(QuestSaveData data)
- {
- activeQuests.Clear();
- completedQuests.Clear();
- foreach (string questId in data.activeQuestIds)
- {
- Quest quest = allQuests.Find(q => q.questId == questId);
- if (quest != null)
- {
- activeQuests.Add(quest);
- }
- }
- foreach (string questId in data.completedQuestIds)
- {
- Quest quest = allQuests.Find(q => q.questId == questId);
- if (quest != null)
- {
- completedQuests.Add(quest);
- }
- }
- }
- }
- [System.Serializable]
- public class QuestSaveData
- {
- public List<string> activeQuestIds;
- public List<string> completedQuestIds;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement