Ejemplo n.º 1
0
        private ControlOutput SaveBinary(Flow flow)
        {
            var binary = promoteToInputPort == true?flow.GetValue <BinarySave>(binarySave) : new BinarySave();

            var loadedSave = append ? BinarySave.Load(GetPath(flow)) : 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);
        }
Ejemplo n.º 2
0
        protected override void Definition()
        {
            if (!usePersistantDataPath)
            {
                path = ValueInput <string>("path", string.Empty);
            }
            fileName = ValueInput <string>(nameof(fileName), string.Empty);
            binary   = ValueOutput <BinarySave>(nameof(binary));

            complete = ControlOutput("complete");
            load     = ControlInput("load", (flow) => {
                flow.SetValue(binary, BinarySave.Load((usePersistantDataPath) ? Application.persistentDataPath + "/data/" + flow.GetValue <string>(fileName) : flow.GetValue <string>(path) + "/" + flow.GetValue <string>(fileName)));
                return(complete);
            });

            Requirement(fileName, binary);
            Requirement(fileName, load);
            Succession(load, complete);
        }