Table of Contents

Tween Creation

The simplest way to create a tween is by using the HyperTweenFactory.CreateTween() method:

using BreezeBlockGames.HyperTween.UnityShared.API;
using BreezeBlockGames.HyperTween.UnityShared.Modules.LocalTransforms.API;
using BreezeBlockGames.HyperTween.UnityShared.Modules.Transforms.API;
using UnityEngine;

namespace HyperTween.Examples
{
    public class CreateTweenExample : MonoBehaviour
    {
        void Start()
        {
            HyperTweenFactory
                // Creates a tween with an optional name that can be used for debugging
                .CreateTween("CreateTweenExample")
                // Sets how long the tween will last
                .WithDuration(1f)
                // Sets which transform to move
                .WithTransform(transform)
                // Sets where the transform should move to
                .WithLocalPositionOutput(new Vector3(1, 2, 3))
                // Plays the tween
                .Play();
        }
    }

}

This tween will move the object's transform to the position (1, 2, 3) over the course of 1 second.

Important

You must call Play() in order for the tween to do anything!

Fluent API

All tween creation methods return a TweenHandle, which provides access to configuration methods for the tween. These methods can be chained for fluent configuration:

HyperTweenFactory.CreateTween("FluentTweenExample")
    .WithDuration(1f)
    .WithTransform(transform)
    .WithLocalPositionOutput(new Vector3(1, 2, 3))
    .WithLocalRotationOutput(Quaternion.Euler(10, 20, 30))
    .WithLocalUniformScaleOutput(2f)
    .Play();

Tween From

By default, tweens being from the existing value when the tween is played, however you can also specify the starting value yourself:

HyperTweenFactory.CreateTween("FromTweenExample")
    .WithDuration(1f)
    .WithTransform(transform)
    .WithLocalPositionOutput(from: new Vector3(1, 2, 3), to: new Vector3(2, 3, 4))
    .Play();

This method is actually slightly more efficient because the starting value does not need to be initialized automatically.

Tween Factories

HyperTweenFactory.CreateTween() uses HyperTweenFactory.Get() under the hood. Using this method is slightly more efficient if you are creating multiple tweens, but it also allows you to create methods for creating tweens that can be reused with different types of factories:

using BreezeBlockGames.HyperTween.UnityShared.API;
using BreezeBlockGames.HyperTween.UnityShared.TweenBuilders;
using UnityEngine;

namespace HyperTween.Examples
{
    public class FactoryTweenExample : MonoBehaviour
    {
        void Start()
        {
            var factory = HyperTweenFactory.Get();

            CreateTween(factory, "TweenA", 1f);
            CreateTween(factory, "TweenB", 2f);
        }

        private static void CreateTween<T>(TweenFactory<T> factory, string name, float duration) 
            where T : unmanaged, ITweenBuilder
        {
            factory.CreateTween(name)
                .WithDuration(duration)
                .Play();
        }
    }
}

Tween Destruction

By default, using the CreateTween() method will cause the created Entity to be destroyed when the tween stops. The ability to reuse tweens is planned for the future.

Entity Targets

In order to use HyperTween to manipulate the LocalTransform of ECS Entities, you can use WithTarget(entity) to cause the tween to output to an arbitrary entity.