private ControlOutput SaveUniversal(Flow flow) { var binary = promoteToInputPort == true?flow.GetValue <UniversalSave>(binarySave) : new UniversalSave() { dataFormat = format }; var loadedSave = append ? UniversalSave.Load(GetPath(flow), format) : null; if (!promoteToInputPort) { for (int i = 0; i < values.Count; i++) { if (!string.IsNullOrEmpty(values[i].key)) { binary.Set(flow.GetValue <string>(names[i]), flow.GetValue <object>(values[i])); } } } if (loadedSave != null) { if (!promoteToInputPort) { for (int i = 0; i < binary.Count; i++) { if (!string.IsNullOrEmpty(values[i].key)) { loadedSave.Set(flow.GetValue <string>(names[i]), flow.GetValue <object>(values[i])); } } } else { var saveKeys = binary.variables.Keys.ToArrayPooled(); var saveValues = binary.variables.Values.ToArrayPooled(); for (int i = 0; i < binary.Count; i++) { loadedSave.Set(saveKeys[i], saveValues[i]); } } Save(flow, loadedSave); lastSave = loadedSave; } else { Save(flow, binary); lastSave = binary; } return(complete); }
protected override void Definition() { if (!usePersistantDataPath) { path = ValueInput <string>("path", string.Empty); } fileName = ValueInput <string>(nameof(fileName), string.Empty); binary = ValueOutput <UniversalSave>(nameof(binary)); complete = ControlOutput("complete"); load = ControlInput("load", (flow) => { flow.SetValue(binary, UniversalSave.Load((usePersistantDataPath) ? Application.persistentDataPath + "/" + flow.GetValue <string>(fileName) : flow.GetValue <string>(path) + "/" + flow.GetValue <string>(fileName), format)); return(complete); }); Requirement(fileName, binary); Requirement(fileName, load); Succession(load, complete); }