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
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;
You will need only these three scripts:
- PTweenPlayerComponent - Root component that holds all tweeners that will be played.
- PTweenComponent - UI Element that will be animated, it holds the configuration of its animation, you can config its position, rotation, scale, and alpha animations.
- PTweenUtil - Static class that has all needed commands for the PTween System.
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.
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();
}
PTween is a free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.