From 15f888835fcc6819a4ff3866c3cad05e6fd5f1ca Mon Sep 17 00:00:00 2001 From: Alistair O'Brien Date: Mon, 31 Jan 2022 22:08:38 +0900 Subject: [PATCH] Add support for custom sample frame rate --- .../AnimationImporter/Editor/AnimationImporter.cs | 2 +- .../Editor/AnimationImporterWindow.cs | 2 ++ .../Editor/Config/AnimationImporterSharedConfig.cs | 14 ++++++++++++++ .../Editor/ImportedData/ImportedAnimationSheet.cs | 4 +++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Assets/AnimationImporter/Editor/AnimationImporter.cs b/Assets/AnimationImporter/Editor/AnimationImporter.cs index 38e1c13..f48afeb 100644 --- a/Assets/AnimationImporter/Editor/AnimationImporter.cs +++ b/Assets/AnimationImporter/Editor/AnimationImporter.cs @@ -439,7 +439,7 @@ private void CreateAnimationAssets(ImportedAnimationSheet animationInfo, string foreach (var animation in animationInfo.animations) { - animationInfo.CreateAnimation(animation, pathForAnimations, masterName, sharedData.targetObjectType, sharedData.pathToSpriteRendererComponent, sharedData.pathToImageComponent); + animationInfo.CreateAnimation(animation, pathForAnimations, masterName, sharedData.targetObjectType, sharedData.pathToSpriteRendererComponent, sharedData.pathToImageComponent, sharedData.animationFrameRate); } } diff --git a/Assets/AnimationImporter/Editor/AnimationImporterWindow.cs b/Assets/AnimationImporter/Editor/AnimationImporterWindow.cs index a323555..f895435 100644 --- a/Assets/AnimationImporter/Editor/AnimationImporterWindow.cs +++ b/Assets/AnimationImporter/Editor/AnimationImporterWindow.cs @@ -168,6 +168,8 @@ sprite values importer.sharedData.spritePixelsPerUnit = EditorGUILayout.FloatField("Sprite Pixels per Unit", importer.sharedData.spritePixelsPerUnit); + importer.sharedData.animationFrameRate = EditorGUILayout.FloatField("Animation Sample Frames", importer.sharedData.animationFrameRate); + GUILayout.Space(5f); ShowTargetLocationOptions("Sprites", importer.sharedData.spritesTargetLocation); diff --git a/Assets/AnimationImporter/Editor/Config/AnimationImporterSharedConfig.cs b/Assets/AnimationImporter/Editor/Config/AnimationImporterSharedConfig.cs index e59bb36..834d68f 100644 --- a/Assets/AnimationImporter/Editor/Config/AnimationImporterSharedConfig.cs +++ b/Assets/AnimationImporter/Editor/Config/AnimationImporterSharedConfig.cs @@ -43,6 +43,20 @@ public float spritePixelsPerUnit } } + [SerializeField] + private float _animationFrameRate = 60f; + public float animationFrameRate + { + get + { + return _animationFrameRate; + } + set + { + _animationFrameRate = value; + } + } + [SerializeField] private pivotAlignmentType _pivotAlignmentType = pivotAlignmentType.Normalized; public pivotAlignmentType pivotAlignmentType diff --git a/Assets/AnimationImporter/Editor/ImportedData/ImportedAnimationSheet.cs b/Assets/AnimationImporter/Editor/ImportedData/ImportedAnimationSheet.cs index a2c7719..6e5359e 100644 --- a/Assets/AnimationImporter/Editor/ImportedData/ImportedAnimationSheet.cs +++ b/Assets/AnimationImporter/Editor/ImportedData/ImportedAnimationSheet.cs @@ -101,7 +101,7 @@ public AnimationClip GetClipOrSimilar(string clipName) return null; } - public void CreateAnimation(ImportedAnimation anim, string basePath, string masterName, AnimationTargetObjectType targetType, string spriteRendererComponentPath, string imageComponentPath) + public void CreateAnimation(ImportedAnimation anim, string basePath, string masterName, AnimationTargetObjectType targetType, string spriteRendererComponentPath, string imageComponentPath, float frameRate) { AnimationClip clip; string fileName = basePath + "/" + masterName + "_" + anim.name + ".anim"; @@ -135,6 +135,8 @@ public void CreateAnimation(ImportedAnimation anim, string basePath, string mast clip.SetLoop(false); } + clip.frameRate = frameRate; + // convert keyframes ImportedAnimationFrame[] srcKeyframes = anim.ListFramesAccountingForPlaybackDirection().ToArray(); ObjectReferenceKeyframe[] keyFrames = new ObjectReferenceKeyframe[srcKeyframes.Length + 1];