diff options
author | chai <215380520@qq.com> | 2024-06-03 10:15:45 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-06-03 10:15:45 +0800 |
commit | acea7b2e728787a0d83bbf83c8c1f042d2c32e7e (patch) | |
tree | 0bfec05c1ca2d71be2c337bcd110a0421f19318b /Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerWriter.cs | |
parent | 88febcb02bf127d961c6471d9e846c0e1315f5c3 (diff) |
+ plugins project
Diffstat (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerWriter.cs')
-rw-r--r-- | Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerWriter.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerWriter.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerWriter.cs new file mode 100644 index 0000000..3fd15ff --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/TextureAtlases/TexturePackerWriter.cs @@ -0,0 +1,45 @@ +using System.Diagnostics; +using System.IO; +using Microsoft.Xna.Framework.Content.Pipeline; +using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; + +namespace MonoGame.Extended.Content.Pipeline.TextureAtlases +{ + [ContentTypeWriter] + public class TexturePackerWriter : ContentTypeWriter<TexturePackerProcessorResult> + { + protected override void Write(ContentWriter writer, TexturePackerProcessorResult result) + { + var data = result.Data; + var metadata = data.Metadata; + + var assetName = Path.GetFileNameWithoutExtension(metadata.Image); + Debug.Assert(assetName != null, "assetName != null"); + + writer.Write(assetName); + writer.Write(data.Regions.Count); + + foreach (var region in data.Regions) + { + var regionName = Path.ChangeExtension(region.Filename, null); + Debug.Assert(regionName != null, "regionName != null"); + + writer.Write(regionName); + writer.Write(region.Frame.X); + writer.Write(region.Frame.Y); + writer.Write(region.Frame.Width); + writer.Write(region.Frame.Height); + } + } + + public override string GetRuntimeType(TargetPlatform targetPlatform) + { + return "MonoGame.Extended.TextureAtlases.TextureAtlas, MonoGame.Extended"; + } + + public override string GetRuntimeReader(TargetPlatform targetPlatform) + { + return "MonoGame.Extended.TextureAtlases.TextureAtlasReader, MonoGame.Extended"; + } + } +}
\ No newline at end of file |