Integrate minigame and courses
This commit is contained in:
@@ -5,8 +5,8 @@ using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[Serializable]
|
||||
// Can not be created from Editor
|
||||
public class Progress
|
||||
{
|
||||
[Serializable]
|
||||
@@ -23,39 +23,34 @@ public class Progress
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: use inheritance to create seperate MinigameProgress and CourseProgress
|
||||
[Header("Course or Minigame")]
|
||||
// TODO: change to course/minigame ScriptableObject reference
|
||||
// Index of item in courses/minigame list object
|
||||
public int index;
|
||||
|
||||
[SerializeField]
|
||||
// values belonging to a certain key, in List (which can be serialized)
|
||||
private List<DataEntry> entries = new List<DataEntry>();
|
||||
|
||||
|
||||
// Add new `key` := `value`, returns `true` if successful
|
||||
public bool Add<T>(string key, T data)
|
||||
public bool AddOrUpdate<T>(string key, T data)
|
||||
{
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
// Search for already existing key
|
||||
foreach (DataEntry entry in entries)
|
||||
{
|
||||
if (entry.key == key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
DataEntry entry = entries.Find(x => x.key == key);
|
||||
|
||||
// Hacky serialization stuff
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
bf.Serialize(ms, data);
|
||||
entries.Add(new DataEntry(key, ms.ToArray()));
|
||||
if (entry != null)
|
||||
{
|
||||
entry.bytes.Clear();
|
||||
entry.bytes.AddRange(ms.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
entries.Add(new DataEntry(key, ms.ToArray()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user