update to unity 6.2, add save system and quest system
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class QuestRegistry : MonoBehaviour
|
||||
{
|
||||
// This will keep a register of all quest data and status
|
||||
public static QuestRegistry Instance { get; private set; }
|
||||
public Dictionary<int, QuestBool[]> QuestBoolMap;
|
||||
public List<int> CompletedQuests;
|
||||
public List<int> ActiveQuests;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// If there is an instance, and it's not me, delete myself.
|
||||
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance = this;
|
||||
Instance.QuestBoolMap = PopulateQuestData();
|
||||
|
||||
PopulateQuestData();
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<int, QuestBool[]> PopulateQuestData()
|
||||
{
|
||||
Dictionary<int, QuestBool[]> questBoolMap = new Dictionary<int, QuestBool[]>();
|
||||
|
||||
// Quest Bool Structure: QID<QuestID>_<Bool Number>_<descriptiveName>
|
||||
// Example: QID11_4_landBurgerGreaseCleared
|
||||
#region 1 - Sam's Plea
|
||||
QuestBool[] QID1_List = new QuestBool[2];
|
||||
|
||||
// QID1_1_hasEnoughStarshards
|
||||
QID1_List[0] = new QuestBool(() =>
|
||||
{
|
||||
return GameManager.Instance.StarShards > 2;
|
||||
});
|
||||
|
||||
// QID1_2_hasHelpedSam
|
||||
QID1_List[1] = new QuestBool(() =>
|
||||
{
|
||||
return GameManager.Instance.Storybools.hasHelpedSam;
|
||||
});
|
||||
|
||||
questBoolMap.Add(1, QID1_List);
|
||||
#endregion
|
||||
|
||||
return questBoolMap;
|
||||
}
|
||||
|
||||
// Save completed quests to disk
|
||||
public void SaveQuestData(ref QuestSaveData data)
|
||||
{
|
||||
data.ActiveQuests = Instance.ActiveQuests;
|
||||
data.CompletedQuests = Instance.CompletedQuests;
|
||||
}
|
||||
|
||||
public void LoadQuestData(QuestSaveData data)
|
||||
{
|
||||
if (data.ActiveQuests != null)
|
||||
{
|
||||
Instance.ActiveQuests = data.ActiveQuests;
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance.ActiveQuests = new List<int>();
|
||||
}
|
||||
|
||||
if (data.CompletedQuests != null)
|
||||
{
|
||||
Instance.CompletedQuests = data.CompletedQuests;
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance.CompletedQuests = new List<int>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class QuestBool
|
||||
{
|
||||
// This let's us define complex behavior for quests. We can also store
|
||||
// raw booleans for this if we have story beats we want to keep track of.
|
||||
public Func<bool> getValue;
|
||||
|
||||
public QuestBool(Func<bool> getValue)
|
||||
{
|
||||
this.getValue = getValue;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct QuestSaveData
|
||||
{
|
||||
public List<int> CompletedQuests;
|
||||
public List<int> ActiveQuests;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user