• 日本語
  • SpriteAttacherを使用した画像変更について

表題の件につきまして、質問させてください。
開発環境:Unity 2021.3.1f1
Spine:4.0.64 Pro

プレイヤーがゲームプレイ時にボタン操作にてキャラクターの装備アイテムを変更した際、
選んだアイテムに応じてキャラクターが手に持っている画像を変更したいと考えております。

これを実装すべく以下コードにてSpriteAttacherを使用して画像変更を試みたところ
InspecterのSpriteAttacher.Sprite欄は更新されますが、
ゲーム画面には初期画像が表示されたままとなっています。

if (Gamepad.current.buttonNorth.isPressed)
{
   spriteattacher.sprite = weaponsprites;
}

リアルタイムにゲーム画面の画像を更新する方法はございますでしょうか?

宜しくお願いいたします。

Related Discussions
...
  • تم التحرير

spriteAttacher.Attach();を呼び出す必要があります。
You need to call spriteAttacher.Attach();.

Thank you for your reply.
I called Attach() right after spriteattacher.sprite.
but, Sprite was not changed.
Is there anything else I need to fix?

if (Gamepad.current.buttonNorth.isPressed)
{
   spriteattacher.sprite = weaponsprites;
   spriteattacher.Attach();
}

申し訳ありません、後でSpriteを渡す場合は Attach()の前にspriteAttacher.Initializeを呼び出す必要があることに気づきました。

spriteAttacher.Initialize(true);
spriteAttacher.Attach();

SpriteAttacherは、スロットに単一のUnity Spriteをアタッチする方法を紹介する古いレガシーサンプルコンポーネントであることに注意してください。 ゲームを作成する場合、このコンポーネントは制限が多すぎたり、操作が面倒になってしまう可能性があります。 代わりに、SpineAPIを使用して実行時にアタッチメントを置き換えることもできます。 アタッチメントを置換する方法、または複数のスキンを新しく組み合わせたスキンに結合する方法については、サンプルシーン Spine Examples/Other Examples/Mix and MatchMix and Match EquipMix and Match Skins をよく確認してみてください。


Sorry, I just noticed that you also need to call spriteAttacher.Initialize before Attach() if you supply the Sprite later.

spriteAttacher.Initialize(true);
spriteAttacher.Attach();

Please note that SpriteAttacher is an old legacy example component which just shows how you can attach a single Unity Sprite at a Slot. If you write a game, this component will likely be far too limited or cumbersome to work with. You may instead want to use the Spine API to replace Attachments at runtime. Please be sure to check out the Spine Examples/Other Examples/Mix and Match, Mix and Match Equip and Mix and Match Skins example scenes on how to replace attachments or combine multiple skins to a new combined skin.

Thank you for your reply.

I was able to get the expected behavior by adding Initialize (true).
We also learned that SpriteAttacher is a legacy sample component.
I would like to confirm the example you gave me.
Thank you very much.

お役に立ててうれしいです、お返事いただきありがとうございました。
Glad it helped, thanks for getting back to us.