tony01

if (collectToasterSpine == null)
{
collectToasterSpine = Instantiate(ToasterSpine);
collectToasterSpine.transform.SetParent(Root.transform);

}
collectToasterSpine.transform.localPosition = new Vector3(4, 2, 0);
if (collectToasterAnimation == null)
{
collectToasterAnimation = collectToasterSpine.GetComponent<SkeletonAnimation>();
collectToasterAnimation.clearStateOnDisable = true;
//设置true 首帧偶现显示stup状态 设置为false 首帧显示path最后一帧
}
if (!collectToasterAnimation.enabled)
{
collectToasterAnimation.enabled = true;
}

TrackEntry trackEntry = collectToasterAnimation.state.SetAnimation(0, "path", false);
trackEntry.Complete += (TrackEntry entry) =>
{
collectToasterSpine.transform.localPosition = new Vector3(5, 2, 0);
collectToasterAnimation.enabled = false;
};
第一次播放没有问题 在第二次播放的时候首帧显示错误 请问是什么原因导致的
tony01
  • Posts: 5

Harald

您能否分享有问题的框架的屏幕截图,并更详细地描述显示不正确的内容? 请同时显示应该显示的内容。
Could you please share a screenshot of the problematic frame, and describe in more detail what is displayed incorrectly? Please also show what should be displayed instead.
User avatar
Harald

Harri
  • Posts: 4335

tony01

当选用animation.clearStateOnDisable = true;是存在首帧显示


正确的显示应该为
tony01
  • Posts: 5

Harald

感谢您的附加信息。看起来好像附件可见性仍设置为设置姿势并且尚未应用动画。

您是否正在使用较旧的 spine-unity 运行时?

所需步骤应如 this论坛主题
根据您发出实例化调用的位置(例如,来自协程等),它可能会在 LateUpdate() 之前缺少对 Update() 的调用。

因此,您可以在实例化调用之后添加以下内容:
[代码]
GameObject instance = Instantiate(clickEffectPre, transform);
var SkeletonAnimation = instance.GetComponent<SkeletonAnimation>();
骨架动画.更新(0); // 这行应该有帮助
骨架动画.LateUpdate(); // 你也可以检查这个额外的行是否也是必要的
[/代码]

这个线程更详细地解释了它:
How to set first frame before animation starting in Unity?
-----

Thanks for the additional information. It looks as if attachment visibility is still set to the setup pose and the animation has not been applied yet.

Are you perhaps using an older spine-unity runtime?

The required steps should be as described on this forum thread:
Depending on where you are issueing the instantiation call (e.g. from coroutines, etc.), it might be missing a call to Update() before LateUpdate().

So you could add the following after your instantiation call:
GameObject instance = Instantiate(clickEffectPre, transform);
var skeletonAnimation = instance.GetComponent<SkeletonAnimation>();
skeletonAnimation.Update(0); // this line should help
skeletonAnimation.LateUpdate(); // you could also check if this additional line is also necessary
This thread explains it in more detail:
How to set first frame before animation starting in Unity?
User avatar
Harald

Harri
  • Posts: 4335

tony01

谢谢。
还有一个性能优化的问题 想请教下。
我场景中存在100多个spine 每帧都会有100多个update() 函数调用消耗
其中有大部分待机动画 只有一帧静态图,怎么优化让一帧静态图的spine的update()函数减少消耗。
tony01
  • Posts: 5

Harald

您可以禁用 SkeletonAnimation 组件,而是从您自己的脚本手动更新它。
您可以查看示例场景Spine Examples/Other Examples/FixedTimestepUpdates,尤其是示例组件SkeletonAnimationFixedTimestep
-----
You can disable the SkeletonAnimation component and instead update it manually from your own script.
You can check out the example scene Spine Examples/Other Examples/FixedTimestepUpdates, especially the example component SkeletonAnimationFixedTimestep.
User avatar
Harald

Harri
  • Posts: 4335


Return to 中国Spine用户