Well. After a day of learning about and converting everything to a list of structs, and getting my display working great with structs, I decided to implement saving the SO to finalize the deal, only to realize I never unimplemented it. It just wasn’t working. It saves, but not between sessions. It saves List<string>
between sessions, but not List<TaskItem>
. So bummed.
The struct portion of my code is:
public struct SubTask{
//public string TaskName {get; set;}
//public bool Completed {get; set;}
//public string Details {get; set;}
string taskName;
bool completed;
string details;
public string TaskName {get {return taskName;} set{taskName = value;}}
public bool Completed {get {return completed;} set{completed = value;}}
public string Details {get {return details;} set{details = value;}}
public override string ToString(){
return string.Format("{0}, {1}, {2}",TaskName, Completed, Details);
}
//public static readonly SubTask Empty = new SubTask();
}
I tried several different ways, but no luck. In my SO, my list is simply:
[SerializeField] List<SubTask> tasks = new List<SubTask>();
Assigning my SO in my editor script is done when loading (I force that - can’t create tasks till a SO is loaded)
void LoadTasksFromSO(){
if (loadTasksSOField.value == null) return;
//taskListSO = loadTasksSOField.value as TaskListSO;
taskListSO = loadTasksSOField.value as TaskListSOSubtask;
activeTasksDisplay.Clear();
//foreach (string task in tasks){
//foreach (string task in taskListSO.GetTasks()){
foreach (SubTask task in taskListSO.GetTasks()){
if (task.Completed){
AddTaskToList(task, completedTasksDisplay);
}else{
AddTaskToList(task, activeTasksDisplay);
}
}
}
And, lastly, my code to save my SO is:
void SaveTasksSO(){
if (taskListSO == null) return;
Debug.Log("saving taskListSO");
EditorUtility.SetDirty(taskListSO);
AssetDatabase.SaveAssetIfDirty(taskListSO);
//AssetDatabase.Refresh(); // course uses this, but it's for updating the database after importing new items
}
Any ideas?