概要
MonoGameのカスタムパイプラインを作成するにあたり参考にしたサイトと、躓いた箇所と対応方法
あとでちゃんとした記事にしたい
参考にしたサイト
このサイトのチュートリアルで、JSON形式のファイルのカスタムパイプラインの作成を参考にした。
躓きポイント
カスタムパイプラインのターゲットフレームワークのバージョンは6.0
Create the MonoGame Content Pipeline Extension Projectの章
ここでプロジェクトのターゲットフレームワークを 6.0 から変更してはいけない。
あとの章で説明されるが、このプロジェクトのビルドdllをMGCBエディタで参照します。
MGCBエディタは.NET6.0対応で8.0以降は対応していない、このプロジェクトのターゲットフレームワークを変更すると後々MGCBエディタが想定の動きをしてくれない。(2025/02/11)
書き込みデータのクラス名を統一
Create the MonoGame Content Pipeline Extension Projectの章
JsonContentProcessorResultクラスを作成する項目で、ソースコードのクラス名と説明文が統一されてない。
これ以降の文でも統一されていないので、都度読み替えましょう。
Runtimeパラメータ
Edit The JsonContentTypeWriterの章
MGCBエディタで設定するパラメータであるRuntimeパラメータを利用していない。
以下のソースコードを
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using TInput = JsonContentPipelineExtension.JsonContentResult;
namespace JsonContentPipelineExtension
{
[ContentTypeWriter]
internal class JsonContentTypeWriter : ContentTypeWriter<TInput>
{
protected override void Write(ContentWriter output, TInput value)
{
output.Write(value.Json);
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return "JsonContentPipeline.JsonContentReader, JsonContentPipeline";
}
}
}
こう置き換えた
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using TInput = JsonContentPipelineExtension.JsonContentProcessorResult;
namespace JsonContentPipelineExtension
{
[ContentTypeWriter]
internal class JsonContentTypeWriter : ContentTypeWriter<TInput>
{
private string _RuntimeType;
protected override void Write(ContentWriter output, TInput value)
{
_RuntimeType = value.RuntimeType;
output.Write(value.Json);
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
if (string.IsNullOrEmpty(_RuntimeType) == false)
{
return _RuntimeType;
}
else
{
return "JsonContentPipeline.JsonContentTypeReader, JsonContentPipeline";
}
}
}
}