- 編集済み
当使用SetActive将SkeletonGraphic显示时会掉帧
项目第一次使用spine时,如 sg.gameObject.SetActive
,Time.deltaTime
在这时就会从0.016s 变成 0.05s 甚至更长。掉帧现象只会在第一次出现,请问spine有没有类似预加载的API?
public SkeletonGraphic sg;
public void SetAnimtion()
{
sg.gameObject.SetActive(true);
sg.skeletonDataAsset = Resources.Load("Test") as SkeletonDataAsset;
sg.Initialize(false);
sg.Skeleton.SetSlotsToSetupPose();
sg.AnimationState.SetAnimation(0, "attack", true);
}
你的代码中最贵的调用就是这个。
The expensive call on your code is this one:
sg.Initialize(false)。
这将从骨架文件(.json
或.skel.bytes
)中加载一切。
This loads everything from the skeleton file (.json
or .skel.bytes
).
如果我没有记错的话,你在发给我们的复制包中使用了.json
。这对加载时间非常不利。请将任何生产资产导出为.skel.bytes
二进制文件,因为它们更小,加载速度更快。
If I remember correctly, you used .json
in a reproduction package that you sent us. This is very bad for load times. Please export any production assets as .skel.bytes
binary files, as they are smaller and load much faster.
关于预加载:你可以在执行其他预加载时调用上面的方法来预加载数据。只是在帧率很重要的时候不要调用它。
Regarding preloading: you can call the methods above to pre-load the data when you perform your other pre-loading. Just don't call it when the framerate matters.
Harald wrote你的代码中最贵的调用就是这个。
The expensive call on your code is this one:sg.Initialize(false)。
这将从骨架文件(
.json
或.skel.bytes
)中加载一切。
This loads everything from the skeleton file (.json
or.skel.bytes
).如果我没有记错的话,你在发给我们的复制包中使用了
.json
。这对加载时间非常不利。请将任何生产资产导出为.skel.bytes
二进制文件,因为它们更小,加载速度更快。
If I remember correctly, you used.json
in a reproduction package that you sent us. This is very bad for load times. Please export any production assets as.skel.bytes
binary files, as they are smaller and load much faster.关于预加载:你可以在执行其他预加载时调用上面的方法来预加载数据。只是在帧率很重要的时候不要调用它。
Regarding preloading: you can call the methods above to pre-load the data when you perform your other pre-loading. Just don't call it when the framerate matters.
如何导出bytes?在我的spine中,没有导出bytes的选项
你必须在导出时选择 "二进制",在JSON下面。
You have to choose Binary
in export, below JSON:
esotericsoftware.com/spineexport#Binary。
然后将默认的二进制扩展名从.skel
改为.skel.bytes
。这对Unity来说是必要的。
Then change the default binary extension from .skel
to .skel.bytes
. This is necessary for Unity.