Hoping for some direction.
Summary I am creating a simple calendar timeline that will have an event with Title and Time. This “event” will appear on a simple timeline organized by time.
ISSUE : I currently do not know the best way to do this. With Dictionaries, with Lists, with custom classes.
I’ve tried all the above methods but my beginner mind isn’t grasping it and I have been unable to Load (See Controller Load() step 3) a debug log of all all the eventParams with a foreach containing mixed variables.
CURRENT SAVE SYSTEM
Save.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Save
{
public List<string> customEvents = new List<string>();
//For Saving example
public string eventParams = "Title";
// Something to save Custom Event Parameters Title & Time
// Able to have mixed Variables
// Add to customEvents list to be pulled from for Timeline
}
CURRENT EVENT CONTROLLER SYSTEM
EventController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection;
public class EventController : MonoBehaviour
{
private Save CreateSaveEvent()
{
Save save = new Save();
save.customEvents.Add(save.eventParams);
return save;
}
public void SaveEvent() // Calls CreateSaveEvent()
{
//1
Save save = CreateSaveEvent();
//2
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/gamesave.save");
bf.Serialize(file, save);
file.Close();
//3
Debug.Log("Event Has Been Save");
}
public void LoadEvent()
{
//1
if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
{
//CLEAR SCREEN??
//2
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath +
"/gamesave.save", FileMode.Open);
Save save = (Save)bf.Deserialize(file);
file.Close();
//3 **** Load events ******
Debug.Log(save.customEvents[0]);
//4 Load Any set variables
Debug.Log("Events Loaded");
}
else
{
Debug.Log("No Events saved!");
}
}
}