예제 #1
0
    void Save()
    {
        // Create flatbuffer class
        FlatBufferBuilder fbb = new FlatBufferBuilder(1);

        // Create our sword for GameDataWhatever
        //------------------------------------------------------

        WeaponClassesOrWhatever weaponType = WeaponClassesOrWhatever.Sword;

        Sword.StartSword(fbb);
        Sword.AddDamage(fbb, 123);
        Sword.AddDistance(fbb, 999);
        Offset <Sword> offsetWeapon = Sword.EndSword(fbb);

        /*
         * // For gun uncomment this one and remove the sword one
         * WeaponClassesOrWhatever weaponType = WeaponClassesOrWhatever.Gun;
         * Gun.StartGun(fbb);
         * Gun.AddDamage(fbb, 123);
         * Gun.AddReloadspeed(fbb, 999);
         * Offset<Gun> offsetWeapon = Gun.EndGun(fbb);
         */
        //------------------------------------------------------

        // Create strings for GameDataWhatever
        //------------------------------------------------------
        StringOffset cname = fbb.CreateString("Test String ! time : " + DateTime.Now);

        //------------------------------------------------------

        // Create GameDataWhatever object we will store string and weapon in
        //------------------------------------------------------
        GameDataWhatever.StartGameDataWhatever(fbb);

        GameDataWhatever.AddName(fbb, cname);
        GameDataWhatever.AddPos(fbb, Vec3.CreateVec3(fbb, 1, 2, 1)); // structs can be inserted directly, no need to be defined earlier
        GameDataWhatever.AddColor(fbb, CompanyNamespaceWhatever.Color.Red);

        //Store weapon
        GameDataWhatever.AddWeaponType(fbb, weaponType);
        GameDataWhatever.AddWeapon(fbb, offsetWeapon.Value);

        var offset = GameDataWhatever.EndGameDataWhatever(fbb);

        //------------------------------------------------------

        // GameDataWhatever.FinishGameDataWhateverBuffer(fbb, offset);
        fbb.Finish(offset.Value);

        // Save the data into "SAVE_FILENAME.whatever" file, name doesn't matter obviously
        using (var ms = new MemoryStream(fbb.DataBuffer.Data, fbb.DataBuffer.Position, fbb.Offset))
        {
            File.WriteAllBytes("SAVE_FILENAME.whatever", ms.ToArray());
            Debug.Log("SAVED !");
        }
    }
예제 #2
0
    void Save()
    {
        mBuilder.Clear();
        mStream.SetLength(0);

        FlatBufferBuilder fbb = mBuilder;
        // FlatBufferBuilder fbb = new FlatBufferBuilder(1);

        // Create our sword for GameDataWhatever
        //------------------------------------------------------

        WeaponClassesOrWhatever weaponType = WeaponClassesOrWhatever.Sword;

        Sword.StartSword(fbb);
        Sword.AddDamage(fbb, 123);
        Sword.AddDistance(fbb, 999);
        Offset <Sword> offsetWeapon = Sword.EndSword(fbb);

        /*
         * // For gun uncomment this one and remove the sword one
         * WeaponClassesOrWhatever weaponType = WeaponClassesOrWhatever.Gun;
         * Gun.StartGun(fbb);
         * Gun.AddDamage(fbb, 123);
         * Gun.AddReloadspeed(fbb, 999);
         * Offset<Gun> offsetWeapon = Gun.EndGun(fbb);
         */
        //------------------------------------------------------

        // Create strings for GameDataWhatever
        //------------------------------------------------------
        StringOffset cname = fbb.CreateString(mTime);

        //------------------------------------------------------

        // Create GameDataWhatever object we will store string and weapon in
        //------------------------------------------------------
        GameDataWhatever.StartGameDataWhatever(fbb);

        GameDataWhatever.AddName(fbb, cname);
        GameDataWhatever.AddPos(fbb, Vec3.CreateVec3(fbb, 1, 2, 1)); // structs can be inserted directly, no need to be defined earlier
        GameDataWhatever.AddColor(fbb, CompanyNamespaceWhatever.Color.Red);

        //Store weapon
        GameDataWhatever.AddWeaponType(fbb, weaponType);
        GameDataWhatever.AddWeapon(fbb, offsetWeapon.Value);

        var offset = GameDataWhatever.EndGameDataWhatever(fbb);

        //------------------------------------------------------

        // GameDataWhatever.FinishGameDataWhateverBuffer(fbb, offset);
        mStream.Write(fbb.DataBuffer.Data, fbb.DataBuffer.Position, fbb.Offset);
        // Debug.Log("size: " + mStream.Length);
    }