Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: 1337GameDev on August 04, 2015, 12:14:44 AM

Title: Had to create a custom toggle tween script, figured I'd share it
Post by: 1337GameDev on August 04, 2015, 12:14:44 AM
I looked for functionality to press a button, and trigger a tween, and then press it again to play that tween in reverse. Sadly, NGUI did not seem to have a simple or easy solution for this, with a simple button.

I created these two scripts:
ToggleTween
Toggle5Tweens

ToggleTween does exactly what you'd expect, it toggles between playing the tween in reverse or forward every time the method "toggleTween" is invoked.

How it works:
1. You assign ToggleTween to a Gameobject
2. You drag and drop the tween you wnat toggled into the script's "Tween Target" field.
3. You assign the method "toggle tween" of that script, to another NGUI button action (or any NGUI system that can call a method, or even through a script yourself).
4. Enjoy

I also made a second script, Toggle5Tweens.
I wanted to create a List of tweens to toggle, but did not want to create an Editor folder and have to manage a custom inspector using the ReorderableList class. So I just chose 5 publically exposed members, as tween targets. I figured this would be sufficient for most use cases.

The script even knows to check if each is null, before invoking them, so all 5 don't need to be filled in.

These scripts are great for making simple "drawers" that can be pulled in and out by a button press, and even multiple tweened elements, from a single button press, without scripting outside NGUI.

I have attached the two scripts. Enjoy!

I hope the developers eventually adopt these and add these as actions for others to use in NGUI. :)