我创建了一个游戏,其中包含大量由精灵表示的2D动画角色。我尝试自动化:
我创建了一个AssetPostprocessor,并在OnPostprocessSprites(Texture2D纹理,Sprite [] sprites)上获得了良好的sprite编号。
然后,我尝试创建如下的.anim文件:
25
然后,我创建了animationOverrideController。
但是当我使用AnimationClip时,什么也没发生。我试图通过拖放创建动画,并且可以正常工作...
我打开了两个.anim文件,看到了:
在我的“脚本”文件中:
for (var y = 0; y < clips.Length; y++)
{
string clipName = "Animation-"+y;
AnimationClip animClip = new AnimationClip();
AnimationClipSettings animClipSett = new AnimationClipSettings();
animClip.frameRate = 25; // FPS
animClip.wrapMode = WrapMode.Default;
animClip.name = clipName;
animClipSett.loopTime = true;
EditorCurveBinding curveBinding = EditorCurveBinding.PPtrCurve("", typeof(SpriteRenderer), "m_Sprite");
ObjectReferenceKeyframe[] spriteKeyFrames = new ObjectReferenceKeyframe[clips[y].Length];
for (int i = 0; i < (clips[y].Length); i++)
{
spriteKeyFrames[i] = new ObjectReferenceKeyframe();
spriteKeyFrames[i].time = i;
spriteKeyFrames[i].value = sprites[i];
}
AnimationUtility.SetAnimationClipSettings(animClip, animClipSett);
AnimationUtility.SetObjectReferenceCurve(animClip, curveBinding, spriteKeyFrames);
if (!AssetDatabase.IsValidFolder("Assets/Character/Animations/" + textureName))
AssetDatabase.CreateFolder("Assets/Character/Animations", textureName);
AssetDatabase.CreateAsset(animClip, "Assets/Character/Animations/" + textureName + "/" + clipName + ".anim");
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
在我生成的.anim文件中,我有:
m_PPtrCurves:
- curve:
- time: 0
value: {fileID: 0}
- time: 1
value: {fileID: 0}
- time: 2
value: {fileID: 0}
- time: 3
value: {fileID: 0}
- time: 4
value: {fileID: 0}
attribute: m_Sprite
path:
classID: 212
script: {fileID: 0}
在YML序列化中,动画帧似乎被忽略了
您知道为什么我的“脚本”动画文件不起作用吗?