Skip to content

An easy way to create UI Animations for a better navigation, in Unity

License

Notifications You must be signed in to change notification settings

lourenco-pedro/PTween

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PTween

An easy way to create animations for your UIs. Create dynamics navigation between interfaces, with a simple and intuitive API.

If you guys have any feedbacks or suggestions about the code, please, send them at pedropereralourenco@gmail.com

Setup

After downloading the library, import the PTween folder into your Unity project. All codes that use the PTween API most have the PTween namespace in them.

using namespace PTween;

Structure

You will need only these three scripts:

  1. PTweenPlayerComponent - Root component that holds all tweeners that will be played.
  2. PTweenComponent - UI Element that will be animated, it holds the configuration of its animation, you can config its position, rotation, scale, and alpha animations.
  3. PTweenUtil - Static class that has all needed commands for the PTween System.

Creating the UI

To create a UI in Unity that uses PTween will be necessary to add a PTweenPlayerComponent in a root panel. There will have all children that use PTweenComponents to be animated.

Eg:

Panel: MainMenu -> PtweenPlayerComponent
    |
    |- Title (Text) PtweenComponent
    |
    |- Start new Game (Button) PtweenComponent
    |
    |- Configuration (Button) PtweenComponent
    |
    |- Quit (Button) PtweenComponent

After creating your panel, the PTweenPlayerComponent will try to get all PTweenComponents in its children. Each PTweenPlayerComponent will be an animation that can be played on your UI, that animation can also be played backward.

Playing the animation

To play the PTweenPlayerComponent, you just need to use the StartPTweenPlayerComponent command, in PTweenUtil.

public static PTweenPlayerInstance StartPTweenPlayerComponent(PTweenPlayerComponent playerComponent, PTweenAnimationDirection animationDirection);

Eg:

public PTweenPlayerComponent _fadeMainMenu;
PTweenPlayerInstance _instance;

void Start()
{
    instance = PTweenUtil.StartPTweenPlayerComponent(_fadeMainMenu, PTweenAnimationDirection.ANIMATE_FORWARD);
}

void Update()
{
    if(instance.IsPlayerFinished)
    { ... }
}

NOTE: When playing a PTweenPlayerComponent, a PTweenPlayerInstance will be instantiate and added into a list inside PTweenUtil, so it animation can be updated. To update that list, just call for the Update() also in PTweenUtil.

Eg:

void Start()
{
    //Adding a instance of that PTweenPlayerAnimation and adding it into a list, so it can be updated at PTweenUtil.Update()
    instance = PTweenUtil.StartPTweenPlayerComponent(_fadeMainMenu, PTweenAnimationDirection.ANIMATE_FORWARD);
}
void Update()
{
    if(instance.IsPlayerFinished)
    { ... }
    
    //Updating all Instances added during the runtime
    PTweenUtil.Update();
}

License

PTween is a free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

About

An easy way to create UI Animations for a better navigation, in Unity

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages