Lean Transition


DOCUMENTATION

What is Lean Transition?

Lean Transition allows you to smoothly animate GameObject and Component settings from their current values, to new values.

Transitions can be as simple as fading menus in and out, to complex sequences with many different branches.

Transitions can be set up in the editor, as well as from code, using exactly the same procedure!



How do I use it?


Editor

First, add transition components to your GameObject. If you click the Add Component button and type in "Transition", you will see a list of all available components. For example, the Transform.localPosition Transition (LeanTransformLocalPosition) component can be added to your GameObject, allowing you t alter the Transform component's localPosition setting.

Next, you must begin the transition. This can be done using many different methods:

Method 1 [Editor Only] Open your transition component's Context Menu (gear icon at the top right), and select Begin All Transitions.
Method 2 Connect your UI button's On Click event to your transition component's Begin All Transitions function.
Method 3 Make a new GameObject with the LeanAnimate component, and drag and drop your transitions GameObject into the Transitions setting. You can now call the LeanAnimate.Begin Transitions function from your UI buttons.
Method 4 Make a new GameObject with the LeanAnimateKeyPress component, and drag and drop your transitions GameObject into the Transitions setting. You can now press the Required Key button, and the animation will begin.


Code

First, you must use the Lean.Transition namespace. Put this at the top of your source file:

using Lean.Transition;

This namespace includes all the extension methods for you to use.

Next, simply replace your normal code with transition variants. For example:

// Instantly change our transform component's localPosition to 10, 10, 10
transform.localPosition = new Vector3(10, 10, 10);

Can be turned into:

// Gradually change our transform component's localPosition to 10, 10, 10 over 0.5 seconds
transform.localPositionTransition(new Vector3(10, 10, 10), 0.5f);

It's as simple as that!

NOTE  All Lean Transition extension methods are named like this with Transition added to the end, so it should be really easy to find them.
NOTE  Not all values have transitions. If you feel like I've missed an important one then please contect me so I can implement it!



How do the ease functions work?


Basic

Ease functions allow you control how a value transitions from its original value to its target value.

Smooth This smoothly accelerates from a speed of 0, reaches max speed in the middle, and smoothly decelerates to 0. This ease is also known as smoothstep.
Accelerate This smoothly accelerates from a speed of 0, and reaches max speed at the end where it instantly stops.
Decelerate This instantly begins at max speed and smoothly decelerates to a speed of 0.
Accelerate This smoothly accelerates from a speed of 0, overshoots the end, and wobbles back and forth before smoothly stopping.
Back This smoothly accelerates from a speed of 0, overshoots the end, and smoothly goes back.
Bounce This smoothly accelerates from a speed of 0, hits the end and bounces several times before coming to a stop.


Advanced

The advanced list of ease functions contains most ease methods commonly seen in other software, though their names may be hard to understand. You can view more information online on sites like THIS.




How do I combine transitions to make a sequence?


Editor

Simply add the LeanJoin component between them.



Code

You must call the JoinTransition() method between them. For example:

transform.
localPositionTransition(new Vector3(10, 10, 10), 0.5f).
JoinTransition().
localPositionTransition(new Vector3(1, 1, 1), 0.5f);



How do I add a delay between transitions?


Editor

Instead of connecting transitions with the LeanJoin component, use the LeanJoinDelay component.



Code

Instead of calling the JoinTransition() method, use the JoinDelayTransition() method. For example:

transform.
localPositionTransition(new Vector3(10, 10, 10), 0.5f).
JoinDelayTransition(5.0f).
localPositionTransition(new Vector3(1, 1, 1), 0.5f);



How do I insert transitions to save time?


Editor

Instead of connecting transitions with the LeanJoin component, use the LeanJoinInsert component.



Code

Instead of calling the JoinTransition() method, use the JoinInsertTransition() method. For example:

transform.
localPositionTransition(new Vector3(10, 10, 10), 0.5f).
JoinInsertTransition(gameObjectWithTransitions).
localPositionTransition(new Vector3(1, 1, 1), 0.5f);



How do I delay or insert without joining?

The JoinDelay and JoinInsert features are same as Delay and Insert, except they automatically have a Join placed at the start and end.


Editor

Instead of connecting transitions with the LeanJoinInsert component, you can manually add the LeanJoin and LeanInsert components.

Instead of connecting transitions with the LeanJoinDelay component, you can manually add the LeanJoin and LeanDelay components.



Code

Instead of calling the JoinDelayTransition() method, you can manually call the JoinTransition() and DelayTransition() methods.

Instead of calling the JoinInsertTransition() method, you can manually call the JoinTransition() and InsertTransition() methods.




How do I change the transition timing?

By default, all transitions are executed in Update, using Unscaled Time.

To change this, simply modify the settings of the LeanTransition component in your scene. If your scene doesn't contain this component, then make a new GameObject and add it.


Editor

Insert the LeanTime() component into your transition, and all transitions after it will use the specified time.

NOTE  This isn't a transition, so you don't need to join it to your other transitions.
NOTE  The transition time will be reset to default the next time you begin transitions.


Code

Simply call the TimeTransition() method, and all transitions after it will use the specified time.

NOTE  To reset the transition time you must call the LeanTransition.ResetTiming method, or call the TimeTransition() method with LeanTime.Default.



How do I perform a custom action?


Editor

You can add the LeanEvent component into your transition, and make the event call a custom function.

NOTE  The LeanEvent component executes after the specified Delay, it's not instant.
NOTE  This isn't a transition, so you don't need to join it to your other transitions.
NOTE  The transition time will be reset to default the next time you begin transitions.


Code

Simply call the EventTransition() method, and the specified action will be invoked after the specified time. For example:

transform.EventTransition(() => Debug.Log("Hello World!"), 1.0f);







Assets

Here's a list of all my other assets, please check them out!

You can also view this list on my Asset Store page.

Lean Touch

Lean Touch

Rapidly develop your game with consistent input across desktop & mobile using Lean Touch. This lightweight asset comes with many modular components, allowing you to customize them to your exact project needs!


Lean Touch+

Lean Touch+

Lean Touch+ is an extension to the popular Lean Touch asset, adding many more example scenes.


Lean Localization

Lean Localization

Lean Localization is a localization library that's designed to be as simple to use as possible for both designers, and programmers.


Lean Pool

Lean Pool

Quickly optimize the performance of your games using Lean Pool. Within minutes you can use this lightweight asset to preload, recycle, and limit the spawning of your prefabs.


Lean Transition

Lean Transition

Quickly polish your games using Lean Transition. This asset allows you to easily tween or animate almost anything in your game, making it transition smoothly.


Lean GUI

Lean GUI

Lean GUI is a colllection of components that extend Unity's GUI system, allowing you to rapidly enhance the user experience (UX) of your game's UI.


Lean GUI Shapes

Lean GUI Shapes

Lean GUI Shapes allows you to quickly add lines, rounded boxes, polygons, and much more to your GUI!


Lean Texture

Lean Texture

Lean Texture allows you quickly modify textures in your project with a range of filters, pack them together into channels, and much more!


Lean Texture+

Lean Texture+

Lean Texture+ is an extension to Lean Texture, adding many new types of texture modification tools!


Paint in 3D

Paint in 3D

Paint all your objects using Paint in 3D - both in game, and in editor. All features are optimized with GPU accelerated texture painting, so you can enjoy consistent performance, even if you paint your objects one million times!


FLOW

FLOW

FLOW allows you to add large scale interactive fluids to your scene - all highly optimized using GPU acceleration.


Destructible 2D

Destructible 2D

Unlock the full potential of your 2D games using Destructible 2D, this asset allows you to quickly convert all your boring solid sprites into fully destructible ones!


Space Graphics Toolkit

Space Graphics Toolkit

Quickly make the space scene of your dreams using Space Graphics Toolkit. This huge collection of space effects can be customized and combined in any way you like, allowing you to quickly make realistic or fantasy worlds. Each feature has been heavily optimized to run on almost any device and platform.


Space Graphics Planets

Space Graphics Planets

Enhance your space scenes using this large pack of high detail volumetric planets. These planets are finished using the powerful planet features from Space Graphics Toolkit (not required).


Volumetric Audio

Volumetric Audio

Unity sounds only emanate from a single point source. This is great for explosions and footsteps, but quite often you need something more advanced. Volumetric Audio is an easy to use package that allows you to define boxes, spheres, capsules, paths, or meshes that sounds can emanate from.






Versions

1.2.1

Updated common library code.



1.2.0

Added transition builder tool.
Added Stop demo scene.
Added Skip demo scene.
Added Repeat demo scene.
Added LeanGameObjectPool.GetClones method.
Renamed LeanAnimation component to LeanManualAnimation.
Renamed LeanTransition.CurrentHead property to PreviousState.
Renamed vector element transitions (e.g. from "positionTransitionX" to "positionTransition_x").
Added LeanAnimationRepeater.RemainingCount setting.
Removed LeanAnimationOnce component (use LeanAnimationRepeater instead).



1.1.4

Fixed joining to transitions with a Duration of 0.
Disabled PlaySound transition Fill button.



1.1.3

Fixed transition players starting with a Speed of 0.
Zero duration transitions now instantly execute.
Added advanced ease types.



1.1.2

Moved main build to Unity 2018.4.13f1.
Simplified LeanPlayer code.
Added per-transition settings to LeanPlayer.



1.1.1

Moved main build to Unity 2018.4.0f1.
Updated documentation.
Added asmdef.



1.1.0

Transitions with quaternions now show euler angles in inspector.
JoinDelay Transition (LeanJoinDelay) now accepts a negative delay time.
All nested transitions now begin after the last transition in the parent completes.
Updated component documentation link.
Renamed auto fill button to fill.
Fill button is now always visible for component that can be filled.
Added Time demo scene.
Added Transform.position.x transition.
Added Transform.position.y transition.
Added Transform.position.z transition.
Added Material float transition.
Added Material color transition.
Added Material vector transition.
Added transition class name to component path name.
Organized transition component names into folders.



1.0.9

Fixed transition timing implementation.
Fixed auto fill button not appearing for transitions without targets.
Added Time.timeScale transition.
Updated common library code.



1.0.8

Fixed inspector expand buttons in UI Elements.



1.0.7

Fixed bug in LeanHelper.cs that prevents making builds.



1.0.6

Updated Common library code.



1.0.5

Fixed issue where transitions wouldn't stop when exiting play mode.
Updated Common library code.
Updated demo scene design.



1.0.4

Fixed LeanPlaySound auto fill button.
Improved inspector code.
Improved code comments.



1.0.3

Added Auto Fill button to transition components.



1.0.2

Updated documentation.



1.0.1

Added Transform.position transition.
Fixed bug when adding multiple events to the same object.
Allowed LeanPlayer.Speed to be toggled off.



1.0.0

First release.







Components

LeanMethod

This is the base class for all transition methods.


LeanState
PreviousState

Each time this transition method registers a new state, it will be stored here.



static float
Smooth
LeanEase ease, float x

This will take the input linear 0..1 value, and return a transformed version based on the specified easing function.



T
GetAliasedTarget<T>
T current

This allows you to get the current Target value, or an aliased override.




LeanPlayer

This class allows you to reference Transforms whose GameObjects contain transition components.

If these transition components define TargetAlias names, then this class will also manage them in the inspector.


List<Entry>
Entries

This stores a list of all Transforms containing transitions that will be played, and their settings.



void
Begin

This method will begin all transition entries.




LeanState

This is the base class for all transition states. When you register a transition (e.g. LeanTransformLocalPosition), it will return an instance of this class, allowing it to be updated by the transition manager.


float
Duration

The transition will complete after this many seconds.



float
Age

The current amount of seconds this transition has been running (-1 for pending Begin call).



List<LeanState>
Prev

If this transition is chained to another, then this tells you which must finish before this can begin.



List<LeanState>
Next

If this transition is chained to another, then this tells you which will begin after this finishes.



bool
Ignore

If this is enabled then the current transition will no longer update, but will otherwise act as normal and not be removed. This is so any transition chain can still work as expected.



float
Remaining

This tells you how many seconds remain until this state completes.



void
BeginAfter
LeanState previousState

If you want this transition to begin after another completes, then call this method.



void
Skip

This will instantly skip this transition to its final state.



void
SkipAll

This will instantly skip this transition to its final state, and all others joined to it.



void
Stop

This will stop this transition at its current position.



void
StopAll

This will stop this transition at its current position, and all others joined to it.




LeanStateWithTarget<T>

This class stores additional base data for transitions that modify a target UnityEngine.Object (most do).


T
Target

This is the target of the transition. For most transition methods this will be the component that will be modified.




LeanTransition

This component updates all active transition methods, both in game, and in the editor.


LeanTiming
DefaultTiming

This allows you to set where in the game loop animations are updated when timing = LeanTime.Default.



static List<LeanTransition>
Instances

This stores a list of all active and enabled LeanTransition instances in the scene.



static LeanTiming
CurrentDefaultTiming

This property gives you the first DefaultTiming instance value.



static int
Count

This tells you how many transitions are currently running.



static LeanState
PreviousState

After a transition state is registered, it will be stored here. This allows you to copy it out for later use.



static LeanState
CurrentQueue

If you want the next registered transition state to automatically begin after an existing transition state, then specify it here.



static LeanTiming
CurrentTiming

This allows you to change where in the game loop all future transitions in the current animation will be updated.



static float
CurrentSpeed

This allows you to change the transition speed multiplier of all future transitions in the current animation.



static Dictionary<string, Object>
CurrentAliases

This allows you to change the alias name to UnityEngine.Object association of all future transitions in the current animation.



static LeanTiming
GetTiming
LeanTiming current = LeanTiming.Default

This method will return the specified timing, unless it's set to Default, then it will return UnscaledTime.



static LeanTiming
GetTimingAbs
LeanTiming current

This method works like GetTiming, but it won't return any unscaled times.



static void
RequireSubmitted

If you failed to submit a previous transition then this will throw an error, and then submit them.



static void
ResetTiming

This will reset any previously called CurrentTiming calls.



static void
ResetQueue

This will reset any previously called CurrentQueue calls.



static void
ResetSpeed

This will reset any previously called CurrentSpeed calls.



static void
ResetState

This will reset the CurrentTiming, CurrentQueue, and CurrentSpeed values.



static void
Submit

This will submit any previously registered transitions, and reset the timing.



static void
BeginAllTransitions
Transform root, float speed = 1.0f

This will begin all transitions on the specified GameObject, all its children, and then submit them.

If you failed to submit a previous transition then this will also throw an error.



static void
InsertTransitions
GameObject root, float speed = 1.0f, LeanState parentHead = null

This will begin all transitions on the specified GameObject, and all its children.



static void
InsertTransitions
Transform root, float speed = 1.0f, LeanState parentHead = null

This will begin all transitions on the specified Transform, and all its children.



static Dictionary<string,System.Type>
FindAllAliasTypePairs
Transform root

This method returns all TargetAliases on all transitions on the specified Transform.




Index

What is Lean Transition?

How do I use it?

How do the ease functions work?

How do I combine transitions to make a sequence?

How do I add a delay between transitions?

How do I insert transitions to save time?

How do I delay or insert without joining?

How do I change the transition timing?

How do I perform a custom action?



Assets

Lean Touch

Lean Touch+

Lean Localization

Lean Pool

Lean Transition

Lean GUI

Lean GUI Shapes

Lean Texture

Lean Texture+

Paint in 3D

FLOW

Destructible 2D

Space Graphics Toolkit

Space Graphics Planets

Volumetric Audio



Versions

1.2.1

1.2.0

1.1.4

1.1.3

1.1.2

1.1.1

1.1.0

1.0.9

1.0.8

1.0.7

1.0.6

1.0.5

1.0.4

1.0.3

1.0.2

1.0.1

1.0.0



Components

LeanMethod

LeanPlayer

LeanState

LeanStateWithTarget<T>

LeanTransition