spine-ue4ランタイム基礎

October 16th, 2023

Spine を Unreal Engine で使用する方法を探求してみましょう!このビデオでは、ブループリントまたは C++ コードで spine-ue4 ランタイムの基本コンポーネントを使用する方法を学びます。

今回のビデオは前回のビデオの内容をベースにコンポーネントの具体的な使い方を紹介している内容になっていますので、spine-ue4ランタイムのインストール方法やスケルトンのインポート方法について知りたい方は、前回のビデオをご覧ください: spine-ue4ランタイム入門

このビデオは役に立ちましたか? ぜひこのビデオについてのご意見、ご感想をSpineフォーラムでお聞かせください!

C#対応版spine-godotのセットアップ

October 2nd, 2023

このブログ記事ではspine-godotでC#を使い始めるために必要なステップと、GDScriptを使用する場合とどのように異なるのかを簡単に説明します。


インストール方法

C#に対応しているビルド済みのGodot4.1エディタとエクスポートテンプレートバイナリはspine-godotランタイムのドキュメントからダウンロードできます。基本的なインストール方法についてはドキュメントに従ってください。


C#プロジェクトのセットアップ

C#対応のGodotエディタバイナリを使用する場合、新しいGodotプロジェクトをセットアップする際に、追加のステップを踏む必要があります。

1. Godotプロジェクトの作成

まず、ダウンロードしたC#対応のGodotエディタバイナリを使用して新しいGodotプロジェクトを作成します。

「Failed to load .NET runtime」エラー

Godotエディタが.NETランタイムのロードに失敗すると、起動時に以下のようなエラーメッセージが表示されます:

これが表示された場合、メッセージ内で説明されている通り、6.0以降の.NET SDK以降をMicrosoftの公式ダウンロードサイトからインストールしてGodotを再起動してください。


2. godot-nugetフォルダの作成

Godotを一度閉じて作成したプロジェクトのフォルダを開いてください。そしてルートディレクトリに godot-nuget という新しいフォルダを作成します。


3. C#アセンブリのコピー

次に、Godot C# アセンブリを godot-nuget フォルダにコピーします。WindowsまたはLinuxを使用されている場合、必要なアセンブリはダウンロードしたGodotエディタのZIPファイル内で見つけられます:

  • Windows: godot-editor-windows-mono.zip\GodotSharp\Tools\
  • Linux: godot-editor-linux-mono.zip/GodotSharp/Tools/

macOSを使用している場合:

  • macOS: Finder上で Godot.app を右クリックして、Show Package Contents(パッケージの内容を表示)を選択して Contents/Resources/GodotSharp/Tools/を開きます。

以下のファイルを godot-nuget フォルダにコピーします:

  • GodotSharpEditor.<version>.snupkg
  • Godot.NET.Sdk.<version>.nupkg
  • Godot.SourceGenerators.<version>.nupkg
  • GodotSharp.<version>.nupkg
  • GodotSharp.<version>.snupkg
  • GodotSharpEditor.<version>.nupkg

<version>の部分はダウンロードしたGodotのバージョンによって異なります。例: 4.1.1.


4. nuget.configファイルの作成

最後に、プロジェクトのルートディレクトリに以下の内容で nuget.config という新しいファイルを作成します:

<configuration>
<packageSources>
    <!-- package source is additive -->
    <add key="godot-nuget" value="./godot-nuget" />
</packageSources>
</configuration>

これは godot-nuget ディレクトリをNuGetパッケージのパッケージソースとして設定します。これにより、NuGetパッケージレジストリから公式のGodot C#アセンブリを取得する代わりに、spine-godotランタイム用のC#バインディングが含まれている godot-nuget ディレクトリのアセンブリが使用されるようになります。


これで再びGodotでプロジェクトを開くと、GDScriptの代わりに、Godotおよびspine-godotのC# APIを使用することができます!


スケルトンをC#でアニメーションさせる

こちらはSpineSpriteノードにアタッチされたC#スクリプトでSpineスケルトンをアニメーションさせる簡単なコードの例です:

C#:

using Godot;
using System;

public partial class SpineSprite : SpineSprite {
   public override void _Ready () {
      GetAnimationState().SetAnimation("run", true, 0);
   }
}

GDScriptで書かれた同じコードと比較すると、各APIがPascalCaseを使用し、C#のコード規約に従って最後にセミコロンを必要とする以外は、ほとんど違いはありません。

GDScript:

extends SpineSprite

func _ready():
   get_animation_state().set_animation("run", true, 0)

GDScriptでは、@onreadyアノテーションを使って関数の外側でスケルトンを取得できますが、C# ではクラス定義の中でAPIを呼び出すことはできないので、関数の中で取得する必要があります。以下は、スケルトンを反転させアニメーションをキューするためのコードをC#で書いた場合とGDScriptで書いた場合の比較です:

C#:

using Godot;
using System;

public partial class SpineSprite : SpineSprite {
   private SpineSkeleton spineSkeleton;
   private SpineAnimationState spineSpriteAnimState;

   public override void _Ready () {
      spineSkeleton = GetSkeleton();
      spineSpriteAnimState = GetAnimationState();
      spineSkeleton.SetScaleX(-1);
      spineSpriteAnimState.SetAnimation("idle", true, 0);
      spineSpriteAnimState.AddAnimation("run", 2, true, 0);
   }
}

GDScript:

extends SpineSprite

@onready var spineSkeleton : SpineSkeleton = get_skeleton()
@onready var spineSpriteAnimState : SpineAnimationState = get_animation_state()

func _ready():
   spineSkeleton.set_scale_x(-1)
   spineSpriteAnimState.set_animation("idle", true, 0)
   spineSpriteAnimState.add_animation("run", 2, true, 0)

GDScriptからC#へのAPIのマッピング方法の詳細については、Godot C#のドキュメントを参照してください。


C#用の例

C#対応版spine-godotのための例を確認したり試したりするには:

  1. spine-runtimes Gitリポジトリをクローンするか、最新バージョンをZIPとしてダウンロードして解凍してください。
  2. spine-runtimes/spine-godot/example-v4-csharp/フォルダを開いて、 project.godotファイルをクリックして開きます。

FileSystemドックのexamplesフォルダ以下で、C#を使った様々なサンプルシーンやスクリプトを見つけることができます。


C#対応版のspine-godotを使用していて何か困ったことがありましたら、遠慮なくSpineフォーラムにて質問を投稿してください!

spine-godot C# support

September 5th, 2023

We're happy to announce that our spine-godot runtime now supports programming using the C# language! You are no longer limited to GDScript. C# support lets you use a feature rich IDE and can greatly increase productivity for complex games.

Please note that currently C# support in Godot 4.x is available only for desktop operating systems. As the Godot team expands platform support, our Godot binaries and export templates will be updated accordingly.

Start using C#

To get started, please visit our spine-godot documentation page and download the latest Godot + Spine binary with C# support for your operating system. Currently we provide binaries for the latest Godot stable release, which is 4.1.1.

Once you have successfully installed the Godot binary, follow the C# project setup guide to either initiate a new project or convert an existing one to utilize C# and Spine-Godot.

For more information on this topic, check out our new blog post about setting up a C# project.

Congratulations! You are now ready to develop your Godot games with Spine and C#!

Discuss this blog post on the Spine forum!