public override void Serialize(string path, TiledNavMesh mesh) { JObject root = new JObject(); root.Add("meta", JToken.FromObject(new { version = new { snj = FormatVersion, sharpnav = Assembly.GetExecutingAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion } })); root.Add("origin", JToken.FromObject(mesh.Origin, serializer)); root.Add("tileWidth", JToken.FromObject(mesh.TileWidth, serializer)); root.Add("tileHeight", JToken.FromObject(mesh.TileHeight, serializer)); root.Add("maxTiles", JToken.FromObject(mesh.MaxTiles, serializer)); root.Add("maxPolys", JToken.FromObject(mesh.MaxPolys, serializer)); var tilesArray = new JArray(); var tiles = (List <MeshTile>)GetPrivateField(mesh, typeof(TiledNavMesh), "tileList"); var tileRefs = (Dictionary <MeshTile, PolyId>)GetPrivateField(mesh, typeof(TiledNavMesh), "tileRefs"); foreach (MeshTile tile in tiles) { PolyId id = mesh.GetTileRef(tile); tilesArray.Add(SerializeMeshTile(tile, id)); } root.Add("tiles", tilesArray); File.WriteAllText(path, root.ToString()); }
public override void Serialize(string path, TiledNavMesh mesh) { JObject root = new JObject(); root.Add("meta", JToken.FromObject(new { version = new { snj = FormatVersion, sharpnav = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion } })); root.Add("origin", JToken.FromObject(mesh.Origin, serializer)); root.Add("tileWidth", JToken.FromObject(mesh.TileWidth, serializer)); root.Add("tileHeight", JToken.FromObject(mesh.TileHeight, serializer)); root.Add("maxTiles", JToken.FromObject(mesh.MaxTiles, serializer)); root.Add("maxPolys", JToken.FromObject(mesh.MaxPolys, serializer)); var tilesArray = new JArray(); var tiles = (List<MeshTile>) GetPrivateField(mesh, typeof(TiledNavMesh), "tileList"); var tileRefs = (Dictionary<MeshTile, PolyId>)GetPrivateField(mesh, typeof(TiledNavMesh), "tileRefs"); foreach (MeshTile tile in tiles) { PolyId id = mesh.GetTileRef(tile); tilesArray.Add(SerializeMeshTile(tile, id)); } root.Add("tiles", tilesArray); File.WriteAllText(path, root.ToString()); }
//!!!!betauser public void Serialize(MemoryStream memoryStream, TiledNavMesh mesh) { using (var binaryWriter = new BinaryWriter(memoryStream, System.Text.Encoding.Default, true)) { binaryWriter.Write(mesh.Origin.X); binaryWriter.Write(mesh.Origin.Y); binaryWriter.Write(mesh.Origin.Z); binaryWriter.Write(mesh.TileWidth); binaryWriter.Write(mesh.TileHeight); binaryWriter.Write(mesh.MaxTiles); binaryWriter.Write(mesh.MaxPolys); var tiles = new List <byte[]>(); var navTiles = new List <NavTile>(mesh.Tiles); binaryWriter.Write(navTiles.Count); foreach (var tile in navTiles) { var baseRef = mesh.GetTileRef(tile); tiles.Add(SerializeMeshTile(tile, baseRef)); } foreach (var tile in tiles) { binaryWriter.Write(tile); } } }
public override void Serialize(string path, TiledNavMesh mesh) { JObject root = new JObject(); root.Add("meta", JToken.FromObject(new { version = new { snj = FormatVersion, sharpnav = typeof(TiledNavMesh).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion } })); root.Add("origin", JToken.FromObject(mesh.Origin, serializer)); root.Add("tileWidth", JToken.FromObject(mesh.TileWidth, serializer)); root.Add("tileHeight", JToken.FromObject(mesh.TileHeight, serializer)); root.Add("maxTiles", JToken.FromObject(mesh.MaxTiles, serializer)); root.Add("maxPolys", JToken.FromObject(mesh.MaxPolys, serializer)); var tilesArray = new JArray(); foreach (NavTile tile in mesh.Tiles) { NavPolyId id = mesh.GetTileRef(tile); tilesArray.Add(SerializeMeshTile(tile, id)); } root.Add("tiles", tilesArray); File.WriteAllText(path, root.ToString()); }
public override void Serialize(string path, TiledNavMesh mesh) { var memoryStream = new MemoryStream(); using (var binaryWriter = new BinaryWriter(memoryStream)) { binaryWriter.Write(mesh.Origin.X); binaryWriter.Write(mesh.Origin.Y); binaryWriter.Write(mesh.Origin.Z); binaryWriter.Write(mesh.TileWidth); binaryWriter.Write(mesh.TileHeight); binaryWriter.Write(mesh.MaxTiles); binaryWriter.Write(mesh.MaxPolys); var tiles = new List <byte[]>(); var navTiles = new List <NavTile>(mesh.Tiles); binaryWriter.Write(navTiles.Count); foreach (var tile in navTiles) { var baseRef = mesh.GetTileRef(tile); tiles.Add(SerializeMeshTile(tile, baseRef)); } foreach (var tile in tiles) { binaryWriter.Write(tile); } } using (var binaryWriter = new BinaryWriter(new FileStream(path, FileMode.Create, FileAccess.Write))) { binaryWriter.Write(Magic); binaryWriter.Write(FormatVersion); var tiledNavMesh = memoryStream.ToArray(); binaryWriter.Write(tiledNavMesh); } }