public void CreateMonsterFlatBufferTypes() { if (_typeBuilder.Structs.Count > 0) { return; } var color = _typeBuilder.AddEnum("Color", BaseType.Byte); color.Add(new EnumVal { Name = "Red", Value = 0, }); color.Add(new EnumVal { Name = "Green", }); // didn't set value color.Add(new EnumVal { Name = "Blue", Value = 2, }); // each of the EnumVals should end up associated to a table. var any = _typeBuilder.AddUnion("Any"); any.Add(new EnumVal { Name = "Monster" }); any.Add(new EnumVal { Name = "Weapon" }); any.Add(new EnumVal { Name = "Pickup" }); var vec3 = _typeBuilder.AddStruct("Vec3"); var vec3_x = vec3.AddField("x", new FlatBuffersType { BaseType = BaseType.Float }); var vec3_y = vec3.AddField("y", new FlatBuffersType { BaseType = BaseType.Float }); var vec3_z = vec3.AddField("z", new FlatBuffersType { BaseType = BaseType.Float }); var minion = _typeBuilder.AddTable("Minion"); var minion_name = minion.AddField("name", new FlatBuffersType { BaseType = BaseType.String }); var monster = _typeBuilder.AddTable("Monster"); var monster_pos = monster.AddField("pos", new FlatBuffersType { BaseType = BaseType.Struct, StructDef = vec3, }); var monster_mana = monster.AddField("mana", new FlatBuffersType { BaseType = BaseType.Short }); var monster_hp = monster.AddField("hp", new FlatBuffersType { BaseType = BaseType.Short }); var monster_name = monster.AddField("name", new FlatBuffersType { BaseType = BaseType.String }); var monster_friendly = monster.AddField("friendly", new FlatBuffersType { BaseType = BaseType.Bool }); var monster_inventory = monster.AddField("inventory", new FlatBuffersType { BaseType = BaseType.Vector, ElementType = BaseType.UByte }); var monster_color = monster.AddField("color", new FlatBuffersType { BaseType = BaseType.UByte, EnumDef = color }); var monster_minions = monster.AddField("minions", new FlatBuffersType { BaseType = BaseType.Vector, ElementType = BaseType.Struct, StructDef = minion }); var monster_main_minion = monster.AddField("mainMinion", new FlatBuffersType { BaseType = BaseType.Struct, StructDef = minion }); // should result in two fields, thingy which is a table and thingy_type for the type enum var monster_thingy = monster.AddField("thingy", new FlatBuffersType { BaseType = BaseType.Union, EnumDef = any }); var weapon = _typeBuilder.AddTable("Weapon"); var weapon_name = weapon.AddField("name", new FlatBuffersType { BaseType = BaseType.String }); var pickup = _typeBuilder.AddTable("Pickup"); var pickup_name = pickup.AddField("name", new FlatBuffersType { BaseType = BaseType.String }); _typeBuilder.Compile(); var red = color.Values.Lookup("Red"); var green = color.Values.Lookup("Green"); var blue = color.Values.Lookup("Blue"); Assert.AreEqual(0, red.Value); Assert.AreEqual(1, green.Value); Assert.AreEqual(2, blue.Value); Assert.AreEqual(0, vec3_x.Value.offset); Assert.AreEqual(4, vec3_y.Value.offset); Assert.AreEqual(8, vec3_z.Value.offset); Assert.IsTrue(vec3.Fixed); Assert.AreEqual(4, monster_pos.Value.offset); Assert.AreEqual(6, monster_mana.Value.offset); Assert.AreEqual(8, monster_hp.Value.offset); Assert.AreEqual(10, monster_name.Value.offset); Assert.AreEqual(12, monster_friendly.Value.offset); Assert.AreEqual(14, monster_inventory.Value.offset); Assert.AreEqual(16, monster_color.Value.offset); }