Skip to content

DevKit

Release: 0.1.0

DevKit is a component and API game development toolkit.

The goal of the asset is to provide stable, reusable boiler-plate code and component building blocks that developers can plug into their project (and extend if desired).

A variety of animation and transform-manipulation components are included. The components are built on top of an extensible programmatic API (full source code included!)

The asset's over 100 prefabs, along with a simple character controller, are used in the provided example scenes to demonstrate DevKit's components. The average polygon count per-model is 150.

Animation API#

The DevKit animation API allows for convenient animation of Transform, RectTransform, and Renderer components via C# extension methods.

Out-of-the-box, the animation API can be used to move, scale, rotate, resize (for RectTransforms), and recolor (for Renderers) with a few simple lines of code.

To get started, be sure to import the Tweening namespace:

1
using FireChickenGames.DevKit.Tweening; 

Animating Transforms#

The animation API uses a builder pattern to animate a GameObject:

1
2
3
var tweenBuilder = transform.Tween();
tweenBuilder.Position(new Vector3(0, 3, 0))
tweenBuilder.Run();

Or using the fluent style:

1
2
3
transform.Tween()
    .Position(new Vector3(0, 3, 0))
    .Run();

Method calls can be chained together:

1
2
3
4
5
transform.Tween()
    .Position(new Vector3(0, 3, 0))
    .Scale(new Vector3(2, 2, 2))
    .Rotation(new Vector3(0, 180, 0))
    .Run();

An action can be called in the builder's run method. For example, to set the GameObject to inactive (or some other operation):

1
2
3
transform.Tween()
    .Position(new Vector3(0, 3, 0))
    .Run(() => gameObject.SetActive(false));

Tweens can be executed in a sequence by passing a boolean to the Run method:

1
2
3
4
transform.Tween()
    .Position(new Vector3(0, 3, 0))
    .Position(new Vector3(0, 0, 0))
    .Run(true);

A third parameter combination exists for the Run method that allows for sequential tweens and a callback function when the animation completes:

1
2
3
4
transform.Tween()
    .Position(new Vector3(0, 3, 0))
    .Position(new Vector3(0, 0, 0))
    .Run(true, () => gameObject.SetActive(false));

Also available are shortcuts to move, scale, and rotate a Transform if the builder pattern is not desirable:

1
2
3
4
transform.TweenPosition(new Vector3(0, 3, 0));
transform.TweenScale(new Vector3(2, 2, 2));
transform.TweenRotation(new Vector3(0, 180, 0));
transform.TweenRotation(Quaternion.Euler(0, 180, 0));

Animating RectTransforms#

In addition to the Transform tween options. For example, a UI component can be rotated like a regular Transform:

1
transform.TweenRotation(new Vector3(0, 360, 0));

Note that resizing is a separate operation from scaling for a RectTransform:

1
rectTransform.TweenSize(new Vector2(500, 500));

Inside of a custom UI component, the Transform can be accessed as a RectTransform.

1
(transform as RectTransform).TweenSize(new Vector2(500, 500));

Animating Renderers#

If a Renderer component has Material, the color and alpha can be animated:

1
2
3
4
renderer.Tween()
    .Color(Color.red)
    .Alpha(0.5f)
    .Run();

Note that the Material must have its Rendering Mode set to Transparent for the alpha transition have an effect.

The builder pattern is optional for these operations:

1
2
renderer.TweenColor(Color.red);
renderer.TweenAlpha(0.5f);

Customizing Animations#

A custom animation duration and ease can be used in all of the animation API operations.

Duration#

The amount of time of the animation's transition can be customized by supplying the Tween builder method with a custom duration:

1
2
3
4
5
6
// All tween animations default to 2 seconds.
transform.Tween(2.0f)
    .Position(new Vector3(0, 3, 0))
    .Scale(new Vector3(2, 2, 2))
    .Rotation(new Vector3(2, 2, 2), 1f) // Except this one that takes 1 second.
    .Run();

Easing#

Be sure to import the ease namespace when specifying an Ease:

1
using FireChickenGames.DevKit.Tweening.Ease; 

An ease has a EaseFunctionType and an EaseDirectionType. The default EaseFunctionType is Linear, but there are many ease functions to choose from.

Ease Function Type Description
Linear Transition at a constant speed.
Quadratic Transition at a polynomial rate of x2.
Cubic Transition at a polynomial rate of x3.
Quartic Transition at a polynomial rate of x3.
Quintic Transition at a polynomial rate of x5.
Sine Transition at the rate of a sine wave's curve.
Back Transition back beyond the start value before continuing to the target value.
Bounce Transition as if the value is bouncing like a ball hitting the ground.
Circular Transition symmetrically in and out at the rate of a quarter circle.
Elastic Transition in a "stretchy" fashion.
Exponential This transition is effectively a combination of the Quartic and Quintic functions.

The default EaseDirectionType is In.

Ease Direction Type Description
In Apply the ease function at the start of the transition.
Out Apply the ease function at the end of the transition.
InOut Apply the ease function at the start and end of the transition.
OutIn Apply the inverted ease function at the start and end of the transition.

Creating an ease is simple:

1
var ease = new Ease(EaseFunctionType.Quadratic, EaseDirectionType.Out);

The ease can be supplied either to the builder (making it the default ease for all of the builder's tweens):

1
2
3
transform.Tween(ease)
    .Position(new Vector3(0, 3, 0))
    .Run();

Alternatively, the ease can be supplied to the individual tween method calls, making it apply only to a specific tween:

1
transform.TweenPosition(new Vector3(0, 3, 0), 0.5f, ease);

Animation Components#

The DevKit animation components are build using the animation API .

Component Description
Animate Animates a GameObject with one or more Animation Settings.
Animate Base The core animation component which other animation components extend.
Animation Settings Contains properties that define a set of animations used to configure other components.
Follow This component moves a GameObject along the x, y, and/or z dimensions of another GameObject.
Move Point To Point Moves a GameObject from one location to another location.
On Collision → Animate Animates a GameObject when collided with.
On Collision → Move To Moves a GameObject to the location of another GameObject.
Recolor Randomly Randomly changes the color of a Material.
Rotate Perpetually Continually rotates a GameObject.

Animate#

The component can provide a simple one-off animation.

Animate component

Or a series of animations.

Animate component with multiple animations

Animation Base#

This is an abstract component that other animation components inherit. It cannot be added directly to a GameObject.

1
2
3
using FireChickenGames.DevKit.Components;

public class AnimationExample : AnimationBase { }

The component provides an extensible base implementation that other animation components use to accomplish specific animation effects.

Animation Settings#

The component is used to visually configure an animation. Certain other components, such as the Animate component, use this component to define which animations they run.

Animate Settings component

Follow#

This component moves a GameObject along the x, y, and/or z dimensions of another GameObject.

Animation Type Option Description
Smooth Smooths the follow motion using Unity's Vector3.SmoothDamp function - useful for a follow camera.
Ease Use a DevKit tween animation to animate the follow motion.
One To One Lock the position of the following GameObject, with no smoothing or animation, to the GameObject it is following.

Follow component

Move Point To Point#

The component moves the animated GameObject from one location to another location.

Move Point to Point component

On Collision → Animate#

The component is used to apply animation configuration from an AnimationSettings component to the animated GameObject.

The AnimationSettings can either come from the colliding GameObject (if it has an AnimationSettings component)...

On Collision Animate component

...or be explicitly set in the inspector.

On Collision Animate with Non-collision Settings component

On Collision → Move To#

The component moves the component's GameObject toward the GameObject it collided with. Colliding objects are filterable by their tag.

On Collision Move To component

Recolor Randomly#

The component changes the color of a material to another random color. This component is mainly for to demonstrate how to animate a color change.

Recolor Randomly component

Rotate Perpetually#

The component simply rotates a GameObject indefinitely.

Rotate Perpetually component

Transform Components#

Component Description
On Collision → Apply Transform Apply a Transform's position, scale, and rotation to a colliding GameObject.
On Collision → Set Parent Set the parent GameObject of the colliding GameObject.

On Collision → Apply Transform#

This component sets the colliding Transform to the specified Transform's position, scale, and rotation. This is useful for "teleporting" a GameObject, e.g. when a player's character falls to its death.

On Collision Apply Transform component

On Collision → Set Parent#

This component simply sets the colliding GameObject's parent. This is useful for implementing moving platforms that allow the player to move with the platform.

On Collision Set Parent component

Other Components#

Component Description
Character Animate a bare-bones character - useful for simple prototypes/demonstrations.
Coroutine Proxy Useful for running coroutines outside of Unity components.
On Collision → Destroy Destroy a GameObject when collided with.
Subject Base An abstract component that adds a simple, reusable mechanism for selecting a GameObject for the child component.

Character#

This component allows a player to control an animated humanoid character model. The simple implementation of running and jumping is suitable for prototypes, demonstrations, testing, and simple platformer games.

Character component

Coroutine Proxy#

This component is used extensively by the DevKit animation API. It should only ever be attached to a GameObject programmatically and for the specific use-case where coroutines need to be run outside of a MonoBehavior.

Coroutine Proxy component

On Collision → Destroy#

This component simply destroys a GameObject when a collision occurs.

On Collision Destroy component

Subject Base#

This is an abstract component that other components extend. It provides a way to reference a GameObject other than the one a derived component is attached to. This adds flexibility when creating components found in DevKit and custom components that depend on DevKit.

Subject Options#

A Subject renders as a dropdown in the inspector with a set of options that defines which GameObject is referenced.

Subject Option Description
Game Object An explicitly specified GameObject.
Self The GameObject the component is attached to.
Parent The parent GameObject of the GameObject the component is attached to. Note that this will be null for a GameObject at the root of the scene.
Player The first available GameObject with the "Player" tag.

Usage#

Using the SubjectBase component is as easy as extending a custom component class with it:

1
2
3
using FireChickenGames.DevKit.Components;

public class SubjectExample : SubjectBase { }

This produces a custom component with a single subject field:

Subject-based example component

Though helpful, the base class is not necessary to use a Subject field:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
using FireChickenGames.DevKit.Core;
using UnityEngine;

public class SubjectExample : MonoBehaviour
{
    public Subject subject = Subject.AsSelf();

    void Start()
    {
        // If this initialization step is missed, the subject.GameObject will
        // be null either "Self" or "Parent" is selected in the inspector.
        subject.SetSelf(gameObject);
    }
}

Accessing the Subject in the GameObject via the subject.GameObject:

1
var gameObjectName = subject.GameObject.name;

It is also possible to get components in a variety of ways from the Subject, similar to how components are retrieved in MonoBehavior classes:

1
2
subject.GetComponent<Collider>();
subject.TryGetComponent<Collider>();

A third way, unique to DevKit, is available that gets OR adds a component if does not exist on the Subject:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
using FireChickenGames.DevKit.Components;
using UnityEngine;

public class SubjectExample : SubjectBase
{
    public Collider myCollider;

    void Start()
    {
        myCollider = subject.GetOrAddComponent(myCollider);
    }
}

The Subject can be programmatically switched:

1
2
3
4
subject.SwitchToGameObject();
subject.SwitchToSelf();
subject.SwitchToParent();
subject.SwitchToPlayer();