Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom sample frame rate #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/AnimationImporter/Editor/AnimationImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Assets/AnimationImporter/Editor/AnimationImporterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
Expand Down