mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
27f7983aaf
example: json data can be stored in sheetdata/player.json, texture can be stored in textures/player.png; player.json contains relative path to texture: image=../textures/player.png don't remove subdirectories from atlas region names, to be able to load multiple animations from one texture atlas without conflicting region names; example: walk/01.png, walk/02.png, ... turn/01.png, turn/02.png, ...
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
// Copyright (c) Craftwork Games. All rights reserved.
|
|
// Licensed under the MIT license.
|
|
// See LICENSE file in the project root for full license information.
|
|
|
|
using System.IO;
|
|
using Microsoft.Xna.Framework.Content.Pipeline;
|
|
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
|
|
using MonoGame.Extended.Graphics;
|
|
|
|
namespace MonoGame.Extended.Content.Pipeline.TextureAtlases;
|
|
|
|
[ContentTypeWriter]
|
|
public class TexturePackerWriter : ContentTypeWriter<TexturePackerProcessorResult>
|
|
{
|
|
protected override void Write(ContentWriter writer, TexturePackerProcessorResult result)
|
|
{
|
|
var tpFile = result.Data;
|
|
var imageAssetName = Path.ChangeExtension(tpFile.Meta.Image, null);
|
|
|
|
writer.Write(imageAssetName);
|
|
writer.Write(tpFile.Regions.Count);
|
|
|
|
foreach (var region in tpFile.Regions)
|
|
{
|
|
var regionName = Path.ChangeExtension(region.FileName, null);
|
|
|
|
writer.Write(region.Frame.X);
|
|
writer.Write(region.Frame.Y);
|
|
writer.Write(region.Frame.Width);
|
|
writer.Write(region.Frame.Height);
|
|
writer.Write(regionName);
|
|
}
|
|
}
|
|
|
|
public override string GetRuntimeType(TargetPlatform targetPlatform)
|
|
{
|
|
return typeof(Texture2DAtlas).AssemblyQualifiedName;
|
|
}
|
|
|
|
public override string GetRuntimeReader(TargetPlatform targetPlatform)
|
|
{
|
|
return typeof(ContentReaders.Texture2DAtlasReader).AssemblyQualifiedName;
|
|
}
|
|
}
|