//TODO Once finished use flatbuffer to save player game data public void SaveProfileToFlat(PlayerProfileModel prof) { float start = Time.realtimeSinceStartup; List <Offset <CharacterModelFlat> > charList = new List <Offset <CharacterModelFlat> >(); FlatBufferBuilder fbb = new FlatBufferBuilder(1); StringOffset item = fbb.CreateString(prof.itemString); foreach (CharacterModel model in prof.characters) { charList.Add(AddCharacterToFlat(fbb, model)); } VectorOffset charVector = fbb.CreateVectorOfTables <CharacterModelFlat>(charList.ToArray()); PlayerProfileFlat.StartPlayerProfileFlat(fbb); PlayerProfileFlat.AddGold(fbb, prof.Gold); PlayerProfileFlat.AddItems(fbb, item); PlayerProfileFlat.AddCharacters(fbb, charVector); Offset <PlayerProfileFlat> offset = PlayerProfileFlat.EndPlayerProfileFlat(fbb); PlayerProfileFlat.FinishPlayerProfileFlatBuffer(fbb, offset); MemoryStream ms = new MemoryStream(fbb.DataBuffer.Data, fbb.DataBuffer.Position, fbb.Offset); File.WriteAllBytes(XmlSaver.PersistentDataPath() + "/SAVEDATA", ms.ToArray()); Debug.Log("Flat Saving time " + (Time.realtimeSinceStartup - start)); }
public static Offset <PlayerProfileFlat> CreatePlayerProfileFlat(FlatBufferBuilder builder, int gold = 0, StringOffset itemsOffset = default(StringOffset), VectorOffset charactersOffset = default(VectorOffset)) { builder.StartObject(3); PlayerProfileFlat.AddCharacters(builder, charactersOffset); PlayerProfileFlat.AddItems(builder, itemsOffset); PlayerProfileFlat.AddGold(builder, gold); return(PlayerProfileFlat.EndPlayerProfileFlat(builder)); }