Skip to content

Custom Easing core for Unity 3D using legacy Animation clip

License

Notifications You must be signed in to change notification settings

pktony/UNITY-EasingCore

Repository files navigation

Animation Utility For Unity

Table of Contents

About

This repository implements animation utility for Unity 3D. It uses legacy animation clip and animation curve. It is implemented base on the official Unity document + a. see referece section for details.

I'm not an expert at animation, so I made an easy way to animate, especially in UIs. I understand that the function has multiple parameters, and not easy to understand at a glance, nevertheless, I tried my best to generalize and simplify the function. Feel free to modify this code! Use your imagination to develop this codes !

These are not tested. Use with caution.

Also take a look at my blog for more detailed explanation. (KOREAN) [Tistory Blog](coming soon)

NOTICE
Some animation curves are not really based on the exact equation. But I tried my best to look similar. see reference where I referenced curves.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Tested On

Unity 2021.3.33f1 Currently live on a product. (AOS / iOS)

Installation

A step by step series of examples that tell you how to get a development env running.

Unity Package git url

Now you are all set ! Enjoy animating !

Tips

Playing Animation :

Use Unity component, "Animation". Create animation clip in run-time, and

Recommended way

private void PlayAnimationClip(AnimationClip clip)
{
   var originalClip = anim.GetClip(clip.name);
   if (originalClip != null) anim.RemoveClip(clip.name);
   anim.AddClip(clip, clip.name);
   anim.Play(clip.name);
}

Animation Loop :

Use Wrapmode in animation clip to control loop mode.
There are Once, Loop, PingPong, Default, ClampForever

Using Hierarchy :

When you want to animate the component in the child component, use hierarchy parmeter.
hierarchy should be the name of the child Transform, and should be joined with '/'
Example:

Parent (Animation Component)
  |-- child_1 (Transform)
  |-- child_2 (Image)
     |-- grandchild
  • when you want to animate alpha of Image in child_1 the hierarchy parameter should look like "Parent/child_1", and Animation Property should be AnimationProperty.Alpha
  • When you want to animate AnchoredPosition of grandchild, the hierarchy parameter should look like "Parent/child_2/grandchild", and Animation Property should be AnimationProperty.AnchoredPosition

Example

Refer to Example Scene in the package.

Animation Samples

Imagealt text

Code Overview

AnimationClipUtility

An extension class for animation. Mostly extends Animation Clip.

SetCurve

public static AnimationCurve SetCurve(this AnimationClip clip, 
    AnimationPropertyType animationPropertyType,
    EaseType easeType,
    float startPos, float endPos, float startTime, float duration,
    string eventFunctionName = "", string destinationHierarchy = "")
Details

Extends AnimationClip. Base function of all the other methods.

Parameters

AnimationPropertyType | AnimationPropertyType Type of the property you would like to animate
EaseType | EaseType Type of curve
startPos(float) | initial value of the animation
endPos(float) | final value of the animation
startTime(float) | initial time of the animation (usually 0).
duration(float) | duration of the animation. eventFunctionName(string) | name of the custom function, you would like to trigger. Leave empty if no event is triggered.
destinationHierarachy(string) | hierarchy of the object you want to animate. Leave empty if animating the object where animation component is attached.

SetCurvePosition

public static void SetCurvePosition(this AnimationClip clip, EaseType easeType,
        Vector2 initialPos, Vector2 targetPos, float startTime, float duration,
        string eventFunctionName = "", string destinationHierarchy = "")
Details

Sets a position animation curve to the clip.

SetCurveRotation

public static void SetCurveRotation(this AnimationClip clip, EaseType easeType,
        Quaternion initialRotation, Quaternion targetRotation, float startTime, float duration,
        string eventFunctionName = "", string destinationHierarchy = "")
Details

Sets a rotation animation curve to the clip.

SetCurveSizeDelta

public static void SetCurveSizeDelta(this AnimationClip clip, EaseType easeType,
        Vector2 initialSize, Vector2 targetSize, float startTime, float duration,
        string eventFunctionName = "", string destinationHierarchy = "")
Details

Sets a Size Delta animation curve to the clip.


AnimationPropertyType

Defines the name of the animation property. i.e.) anchored position => m_AnchoredPosition

Supported Types

AnchoredPostion (X, Y)
Rotation (X, Y, Z)
SizeDelta (X, Y)
Scale (X, Y, Z)

TMPRO Font Size
Sprite
Alpha

You can actually add any properties(alpha, position, pivot, anchor, etc) yourself as long as you know the Unity's internal name for each properties.


EasingCore

EaseType

Linear,
EaseInOut,
EaseOut,
EaseIn,
Constant,
ExponentialOut,
ExponentialIn,
ExponentialInOut,
EaseInBack,
EaseOutBack,
EaseInOutBack,
BounceOut,
BounceIn,

Reference

  • Figma Learn - Prototype easing and spring animations
  • Unity-EasingLibraryVisualization
  • Easing Cheatsheet
  • Unity - AnimationCurve
  • Unity - AnimationClip
  • Unity - Keyframe

About

Custom Easing core for Unity 3D using legacy Animation clip

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages