• 日本語
  • SkeletonDataAssetの差し替えと反映について

通信画面のようなものを作っています。
I'm making a kind of communication screen.

Spineを使って素体の出し変えをしたいと思います。
I would like to use Spine to change the object.

最初はSpineには何も入っていません。
At first, there is nothing in Spine.


_SkeletonDataAsset = Resources.Load<SkeletonDataAsset>("Spine Examples/Spine Skeletons/Spineunitygirl/Doi_SkeletonData");
SpineCG2.GetComponent<SkeletonAnimation>().skeletonDataAsset = _SkeletonDataAsset;

通信が始まるとスクリプトにより右側に画像を出します。
(右側のSpineは毎回女の子とは限りません。)
When the communication starts, the script will show the image on the right side of the screen.
(The Spine on the right isn't necessarily a girl every time.)


SpineCG2.GetComponent<SkeletonAnimation>().skeletonDataAsset = null;

通信が終わるとSpineの画像を消したいと思っています。
ただし、このときゲームオブジェクトはactiveのままにしたいとおもっています。

I would like to delete the Spine image when the communication is over.
However, I would like to leave the game object active at this time.

簡略化したコードを書くとこちらです。
Here's a simplified version of the code

void Update()
{
    if (Input.GetButtonDown("Fire1"))
    {
        _SkeletonDataAsset = Resources.Load<SkeletonDataAsset>("Spine Examples/Spine Skeletons/Spineunitygirl/Doi_SkeletonData");
        SpineCG2.GetComponent<SkeletonAnimation>().skeletonDataAsset = _SkeletonDataAsset;
        SpineCG2.GetComponent<SkeletonAnimation>().Skeleton.Skin = null;
    }

    if (Input.GetButtonDown("Fire2"))
    {
        SpineCG2.GetComponent<SkeletonAnimation>().skeletonDataAsset = null;
    }


}
Related Discussions
...

見逃している呼び出しは skeletonAnimation.Initialize(true); ではないかと思います。
リソースからのskeletonDataのロードとアンロードを扱う古いスレッドがここにあります。
How to dynamically load/unload Skeleton Data Assets
I think the call you are missing is skeletonAnimation.Initialize(true);.
There is an older thread that deals with loading and unloading skeletonData from Resources here, in case it helps:
How to dynamically load/unload Skeleton Data Assets

SkeletonGraphic で動作する短いコードサンプルを別のスレッドから翻訳したものを以下に追加しましたが、SkeletonAnimation でも同様に動作するはずです。
I have added a translation from another thread with a short code sample that works with SkeletonGraphic, however it should work with SkeletonAnimation just as well:

initialSkinNameも設定する必要があるかもしれないことに注意してください。そうしないと、以前に設定したスキン名の残りが Initialize() で古いスキン名を探してエラーになる可能性があることに注意してください。
Please note that you might have to set initialSkinName as well, otherwise it will be a remainder of the previously set skin name that could be causing an error during Initialize(), looking for the old skin name.

SkeletonGraphicの場合は、SetMaterialDirty()でMaskableGraphic部分を更新する必要があります。
In the case of SkeletonGraphic, you also have to be sure to update the MaskableGraphic part via SetMaterialDirty().

関連するコードは以下の通りです:
The relevant code is as follows:

skeletonGraphic.initialSkinName = "goblin";
skeletonGraphic.startingAnimation = "";

skeletonGraphic.Initialize(true);

skeletonGraphic.AnimationState.SetAnimation(0, "walk", true);
skeletonGraphic.SetMaterialDirty(); // `SkeletonAnimation`を使用している場合はこの行は削除できます
6 jours plus tard

ありがとうございます。
もらった情報と私の知っている情報を組み合わせて、これで消えることを確認しました。

public void SpineGirlDisappear()
{
    SpineGirl.GetComponent<SkeletonAnimation>().skeletonDataAsset = null;
    SpineGirl.GetComponent<SkeletonAnimation>().ClearState();
    SpineGirl.GetComponent<SkeletonAnimation>().Initialize(true);
 
}

返事をくれてありがとう うまくいったと聞いて嬉しいよ
Thanks for getting back to us. Glad to hear you got it worked out.