public static void Execute() { IEnumerable <Sprite> sprites = Selection.objects.OfType <Sprite>(); if (!sprites.Any()) { Debug.LogWarning("Please selecting sprites."); return; } List <SpriteKeyframeDefinition> spriteKeyframes = sprites .OrderBy(it => it.name) .Select((Sprite sprite, int index) => new SpriteKeyframeDefinition { Value = sprite, Time = 0.1F * index, }) .ToList(); SpriteAnimationClipDefinition definition = new SpriteAnimationClipDefinition { Name = "Sample", SpriteKeyframes = spriteKeyframes, WrapMode = WrapMode.Loop, IsLoop = true, FrameRate = 60.0F }; string path = "Assets/Sample.anim"; AnimationClip animClip = SpriteAnimationClipCreator.Create(definition); AssetDatabase.CreateAsset(animClip, path); }
static AnimationClip CreateAnimationClip(bool isLoop, string name, float frameDuration, params Sprite[] sprites) { List <SpriteKeyframeDefinition> spriteKeyframes = sprites .Select((sprite, index) => new SpriteKeyframeDefinition { Value = sprite, Time = frameDuration * index }).ToList(); return(SpriteAnimationClipCreator.Create(new SpriteAnimationClipDefinition { SpriteKeyframes = spriteKeyframes, WrapMode = isLoop ? WrapMode.Loop : WrapMode.Default, IsLoop = isLoop, FrameRate = 4F, Name = name, })); }