Source Code Progress as of Day 1

GitHub - yjlintw/Tweenie at blog-day1

What is Tweenie?

Tweenie is a Unity package that enables tween animations. The main purpose of developing this package was to practice my API development skills. This blog will document the design decisions that I have made and I am open to receiving feedback and suggestions for better code library and API design practices.

How does Tweenie work?

Current API (…which will change during the journey of development)

Currently, Tweenie only has one method, but more features will be added in the future. The current method is:

public static ITweener To<T>(Func<T, T> param, T fromValue, T toValue, float duration, Func<T,T,float,T> lerpFunc)

This method creates a new Tweener for animating a value of type T. The param parameter is a function that returns the value to be animated. The fromValue and toValue parameters specify the start and end values of the animation. The duration parameter specifies the length of the animation in seconds. The lerpFunc parameter is a function that performs linear interpolation between two values of type T.

For basic types like float, Vector3, and Color and more, Tweenie provides overloaded versions of the To method that take care of the lerp function by default. For example, to animate a float value, you can use the following code:

Tweenie.To(x => myValue = x, oldValue, newValue, duration);

In this example, the x => myValue = x lambda function sets myValue to the interpolated value on every frame. The start value is oldValue, the end value is newValue, and the duration of the animation is duration.

Singleton? That sounds evil!

The Singleton pattern was used for Tweenie to ensure that only one instance of the Tweenie game object exists in the scene. This is necessary to hook into the game loop in Unity. Additionally, Tweenie allows users to call static methods like To anywhere in their code to create new Tweener animations.