private void OnDestroy() { // Prevents unnecessary saving if we're not destroying the original BlackboardController if (instance != this) { return; } BlackboardStateSave save = SaveBlackboardState(); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/SaveFile"); bf.Serialize(file, save); file.Close(); }
private BlackboardStateSave SaveBlackboardState() { BlackboardStateSave save = new BlackboardStateSave(); foreach (KeyValuePair <string, BlackboardVariable> entry in blackboard.AsList()) { if (entry.Value == null || entry.Value.persistenceType == PersistenceType.AlwaysPersist) { continue; } if (entry.Value.persistenceType == PersistenceType.SavedToFile) { save.savedEntries.Add(new KeyValuePair <string, BVarSave>(entry.Key, entry.Value.CreateSave())); } entry.Value.UndoChanges(); } return(save); }