TweenToggle Documentation

Getting Started

TweenToggle consists of two major components – the TweenToggle family classes and TweenToggleDemux.

TweenToggle

The TweenToggle family classes each control a type of tweening:

  • TweenTogglePosition – object translation
  • TweenToggleRotation – object rotation in euler angles
  • TweenToggleScale – object scaling
  • TweenToggleAlpha – object transparency (Note: this currently works for GUI elements)
  • TweenToggleAlphaCanvasGroup – GUI CanvasGroup transparency

While these scripts will cover most tweening needs, the base TweenToggle class can be easily extended with your own custom class to fit your needs.

TweenToggleDemux

While the TweenToggle family classes can each function as a component individually, TweenToggleDemux is used to control a group of TweenToggle classes. Think of it as a control panel that fires off instructions to all its relevant workers, telling them to either all show or hide.

Say your game is made of different UI states: Main Menu, In Game, Game Over. Each of the states can have a TweenToggleDemux to control everything that needs to show/hide when entering or leaving the states. That way everything is nicely encapsulated into their own components.

 

Example Scene

Check out the example scene ‘TweenToggleScene’ inside Assets > TweenToggle > Examples > TweenToggleScene

Setup

Install LeanTween Plugin

  1. Go to Window > Asset Store
  2. Search for LeanTween and install the plugin
  3. Compile errors should go away

Set script execution order

  1. Go to Edit > Project Settings > Script Execution Order
  2. Add TweenToggleDemux and TweenToggle
  3. Drag the two scripts anywhere ABOVE the DefaultTime bar
  4. TweenToggleDemux should be ABOVE TweenToggle

That’s it, you’re done!

TweenToggle

Tween toggle is an abstract class. The actual components that you will be using are all children of this class.

 

Universal Settings

Starts Hidden – Is the object showing when Awake is called? Note: Checking this does not invoke any hide callbacks.

Use Estimated Time – Check this if your timescale is not 1 when tween happens. Useful for game pauses where timescale is set to 0.

Inactive When Hidden – Should the object be inactive when in the hide state? Useful for decreasing the amount of batch calls when the objects are off-screen.

Hide Immediately – A temporary setting if you want to immediately hide the UI for custom cases. This option remembers your initial settings so it will still function normally if it is unchecked again.

Show Delay – How many seconds to wait before object starts showing animation.

Show Duration – How many seconds to last for showing animation.

Show Ease – Easing function for the show animation.

Hide Delay – How many seconds to wait before object starts hiding animation.

Hide Duration – How many seconds to last for hiding animation.

Hide Ease – Easing function for the hide animation.

OnShowComplete – Works the same way as an Unity GUI Button. Click the ‘+’ and assign methods to invoke when the show animation is complete.

OnHideComplete – Works the same way as an Unity GUI Button. Click the ‘+’ and assign methods to invoke when the hide animation is complete.

 

PositionTweenToggle Settings

Tween Delta – Amount to translate when hidden.

 

RotationTweenToggle Settings

Tween Delta – Amount to rotate when hidden. Inputs are represented in Euler angles.

 

ScaleTweenToggle Settings

Tween Delta – Amount to scale when hidden.

 

AlphaTweenToggle & AlphaTweenToggleCanvasGroup Settings

Tween Delta – Amount delta fade when hidden. Alphas are represented as a 0-1 float. Use -1 for a complete fade.

using UnityEngine;

public class TweenToggleExample : MonoBehaviour {
    public TweenToggle tween;

    public void ShowTween(bool isOn){
        if(isOn){
            tween.Show();
        }
        else{
            tween.Hide();
        }
    }
}

TweenToggleDemux

TweenToggleDemux is the override controller for a group of different TweenToggle scripts. This script will override StartsHidden and HideImmediately in each referenced TweenToggle.

 

Settings

Allow Toggle While Tweening – Allows for interruptions in toggle while animating.

Starts Hidden – Is the TweenToggleDemux showing when Awake is called? Note: Checking this does not invoke any hide callbacks.

Hide Immediately – A temporary setting if you want to immediately hide the UI for custom cases. This option remembers your initial settings so it will still function normally if it is unchecked again.

UI Ray Cast Block – If there is a CanvasGroup assigned, it will block the raycast on show, disabling ray cast to any objects behind it.

On Show Complete – Callback to invoke when show is complete. Similar to assigning a Unity button.

On Hide Complete – Callback to invoke when hide is complete. Similar to assigning a Unity button.

Tween Toggle List – List of all the TweenToggles that it controls.

Note: If an object only has one TweenToggle, simply drag it onto the list. If an object has multiple TweenToggle components, you will have to lock the current inspector with the object itself, open a new one with the TweenToggleDemux and drag each relevant TweenToggle component into the list. I will try my best to see if there is a better way to accomplish this.

using UnityEngine;

public class TweenToggleDemuxExample : MonoBehaviour {
    public TweenToggleDemux demux;

    public void ShowDemux(bool isOn){
        if(isOn){
            demux.Show();
        }
        else{
            demux.Hide();
        }
    }
}

Coming soon!