Unity Spine プラグインは以下を使用します
Spine は、ゲーム開発用の 2D スケルトン アニメーションです。Unity 自体はスパイン ファイルの再生をサポートしていないため、これをサポートするには Unity Spine プラグインをインストールする必要があります。
Spine プラグインのダウンロードとインストール
Spine プラグインは、Spine の公式ドキュメントにあります。
注: Spine-unity コンポーネント パッケージが、アーティストが使用する Spine のバージョンに対応していることを確認する必要があります。バージョンが合っていないと正常に動作しない可能性があります。
バージョン ファイルは、Spine プラグイン ディレクトリにありますversion.txt
。ファイルの内容はおおよそ次のとおりです。
この Spine-Unity ランタイムは、Spine Editor
バージョン: 3.8.xx パッケージ バージョン:
sinner-unity-3.8-2020-10-28.unitypackageからエクスポートされたデータを処理します。
スパインリソースのインポート
Spine リソースは、エクスポート時に Json 形式またはバイナリ形式を選択できます。SkeletonDataAsset
エクスポート時にいくつかの設定を行う必要があります。それ以外の場合は、 を手動でドラッグSkeleton JSON
アンドドロップする必要がありますAtlas Assets
。
-
Json エクスポートJson エクスポートを使用すると、
デフォルトで.png
.json
.atlas
これら 3 つのファイルが生成されます。Spineプラグインでは.atlas
正常にファイルを認識できないため、エクスポート時にサフィックス名を設定する必要があります.atlas.txt
(手動で変更することも可能)。 -
バイナリ エクスポート
バイナリ エクスポートは上記と同様で、.png
.skel
.atlas
次の 3 つのファイルを生成します。Spine プラグインを認識しやすくするには、これを に変更する必要があります.png
.skel.bytes
.atlas.txt
。
上記の設定が完了すると、フォルダーからUnityProject
ウィンドウに直接ドラッグ&ドロップすることができます。
注: JSON ではなくバイナリ形式でエクスポートすると、ファイル サイズが小さくなり、読み込みが速くなります。
スパイン リソースのインポート ソース コード
Spine プラグインのこのクラスはAssetPostprocessorSpineEditorUtilities
を継承しており、リソースをインポートするときに対応する関数をトリガーします。すべてのリソースがインポートされた後にスパイン プラグインが呼び出されていることがわかります。
public partial class SpineEditorUtilities : AssetPostprocessor {
// ...
// Auto-import post process entry point for all assets
static void OnPostprocessAllAssets (string[] imported, string[] deleted, string[] moved, string[] movedFromAssetPaths) {
// ...
AssetUtility.HandleOnPostprocessAllAssets(imported, texturesWithoutMetaFileCopy);
// ...
}
}
次に、AssetUtility
ファイル拡張子がこのクラスで処理されます。ソース コードから、Spine プラグインがサフィックスに従ってロードするかどうかを認識することがわかります。また、必要なサフィックスに一致するようにコードを変更することもできます (ただし、これはお勧めしません)。
public static class AssetUtility {
// ...
public static void ImportSpineContent (string[] imported, List<string> texturesWithoutMetaFile,
bool reimport = false) {
// ...
foreach (string str in imported) {
string extension = Path.GetExtension(str).ToLower();
switch (extension) {
case ".atlas":
if (SpineEditorUtilities.Preferences.atlasTxtImportWarning) {
Debug.LogWarningFormat("`{0}` : If this file is a Spine atlas, please change its extension to `.atlas.txt`. This is to allow Unity to recognize it and avoid filename collisions. You can also set this file extension when exporting from the Spine editor.", str);
}
break;
case ".txt":
if (str.EndsWith(".atlas.txt", System.StringComparison.Ordinal))
atlasPaths.Add(str);
break;
case ".png":
case ".jpg":
imagePaths.Add(str);
break;
case ".json":
var jsonAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(str);
if (jsonAsset != null && IsSpineData(jsonAsset, out compatibilityProblemInfo))
skeletonPaths.Add(new PathAndProblemInfo(str, compatibilityProblemInfo));
break;
case ".bytes":
if (str.ToLower().EndsWith(".skel.bytes", System.StringComparison.Ordinal)) {
if (IsSpineData(AssetDatabase.LoadAssetAtPath<TextAsset>(str), out compatibilityProblemInfo))
skeletonPaths.Add(new PathAndProblemInfo(str, compatibilityProblemInfo));
}
break;
}
}
// ...
}