示例#1
0
    // save objects
    public void SaveToFile()
    {
        // file stream
        DataManager fileStream = new DataManager();
        string      fullFile;

        fileStream.ClearAllDataRecordsFromManager(); // clear existing content

        // if children should be added, its updated before saving.
        if (addChildrenOnSave)
        {
            AddChildrenToList();
        }

        // set record file and save
        fullFile = GetFileWithPath();
        fileStream.SetDataFile(fullFile);

        // adds all elements in the list.
        foreach (GameObject element in objects)
        {
            SerializedObject entity = SerializableObject.Pack(element);
            byte[]           data   = DataManager.SerializeObject(entity);

            // adds data
            fileStream.AddDataRecordToManager(data);

            // new
            byte[]           tempData = fileStream.GetDataFromManager(fileStream.GetDataRecordAmount() - 1);
            object           tempObj  = DataManager.DeserializeObject(tempData);
            SerializedObject tempEty  = (SerializedObject)tempObj;
            tempEty.GetType();
        }

        fileStream.SaveDataRecords();

        // if the save record didn't create or edit a file, the name must be invalid.
        if (!fileStream.FileAvailable())
        {
            Debug.Log("File could not be found, or opened.");
            return;
        }

        //  clear ocntent so it can be reused.
        fileStream.ClearAllDataRecordsFromManager();
        Destroy(fileStream);

        Debug.Log("Save Successful!");
    }