Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Jernau on June 16, 2012, 05:00:30 PM

Title: iTween FadeTo
Post by: Jernau on June 16, 2012, 05:00:30 PM
I was having trouble (http://hutonggames.com/playmakerforum/index.php?topic=1764.0) figuring out how to fade a GameObject to invisible. So I added the iTween FadeTo (http://itween.pixelplacement.com/documentation.php#FadeTo) method as a PlayMaker Action.

I copied the Tooltip text dircetly from the iTween API documentation, but I believe that the alpha variable documentation might be incorrect and should probably read "The end alpha value of the animation."

This is my first ever PlayMaker Action, so take it with a large pinch of salt!

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("iTween")]
[Tooltip("Changes a GameObject's opacity over time.")]
public class iTweenFadeTo: iTweenFsmAction
{
[RequiredField]
public FsmOwnerDefault gameObject;

[Tooltip("iTween ID. If set you can use iTween Stop action to stop it by its id.")]
public FsmString id;

[Tooltip("The initial alpha value of the animation.")]
public FsmFloat alpha;
[Tooltip("Whether or not to include children of this GameObject. True by default.")]
public FsmBool includeChildren;
[Tooltip("Which color of a shader to use. Uses '_Color' by default.")]
public FsmString namedValueColor;
[Tooltip("The time in seconds the animation will take to complete.")]
public FsmFloat time;
[Tooltip("The time in seconds the animation will wait before beginning.")]
public FsmFloat delay;
[Tooltip("The shape of the easing curve applied to the animation.")]
public iTween.EaseType easeType = iTween.EaseType.linear;
[Tooltip("The type of loop to apply once the animation has completed.")]
public iTween.LoopType loopType = iTween.LoopType.none;

public override void Reset()
{
base.Reset();
id = new FsmString{UseVariable = true};
alpha = 0f;
includeChildren = true;
namedValueColor = "_Color";
time = 1f;
delay = 0f;
}

public override void OnEnter()
{
base.OnEnteriTween(gameObject);
if(loopType != iTween.LoopType.none) base.IsLoop(true);
DoiTween();
}

public override void OnExit(){
base.OnExitiTween(gameObject);
}

void DoiTween()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;

itweenType = "fade";
iTween.FadeTo(go, iTween.Hash(
                              "name", id.IsNone ? "" : id.Value,
      "alpha", alpha.Value,
      "includechildren", includeChildren.IsNone ? true : includeChildren.Value,
      "NamedValueColor", namedValueColor.Value,
      "time", time.Value,
                              "delay", delay.IsNone ? 0f : delay.Value,
                              "easetype", easeType,
                              "looptype", loopType,
                              "oncomplete", "iTweenOnComplete",
                              "oncompleteparams", itweenID,
                              "onstart", "iTweenOnStart",
                              "onstartparams", itweenID,
                              "ignoretimescale", realTime.IsNone ? false : realTime.Value 
                              ));
}
}
}
Title: Re: iTween FadeTo
Post by: smiffy on June 27, 2012, 06:01:35 PM
Worked perfectly for me. Many thanks for the share, much appreciated!
Title: Re: iTween FadeTo
Post by: jeanfabre on June 28, 2012, 01:35:22 AM
Hi,

 Very good for a first action, congrats!

 One thing: Call "Finish()" after you've done your work in the OnEnter() method so that the state can proceed futher it's actions and if none are found, then it will trigger the "FINISH" event.


 bye,

 Jean
Title: Re: iTween FadeTo
Post by: Mayhem on March 07, 2013, 08:21:51 AM
Hm, i copied the Script, and it integrated well, but it didn't work quite well. Nothings fading out :/

Made an object and a teststate.
In my first state i just use this action, but it doesn't fade out. Are there certain settings?
Title: Re: iTween FadeTo
Post by: 3d_Artist1987 on March 07, 2013, 09:07:30 AM
your shader have alpha value property?
Title: Re: iTween FadeTo
Post by: Mayhem on March 07, 2013, 09:19:55 AM
The Thing is i want to fade out an nGUI Item!
So i can't directly access the GameObject itself, i have to access to the UISpriteComponent itself. I managed to do that via GetProperties and could store the Alphafloat in a custom Variable.

But then i don't know how to use that with this script :/
Title: Re: iTween FadeTo
Post by: tankun on June 06, 2013, 08:24:05 AM
This works with a GUI Texture object as well.

I wonder if it's possible to fade in with this action as well?
Title: Re: iTween FadeTo
Post by: ExprSt on November 27, 2013, 04:09:37 PM
I'm new on Playmaker and couldn't figure it out. May anyone help? Maybe make a video?
Title: Re: iTween FadeTo
Post by: johanesnw on January 16, 2014, 04:25:35 AM
wow nice share. is it only for fade out?
i cannot fade in with this
Title: Re: iTween FadeTo
Post by: sxkx360 on January 17, 2014, 07:37:59 AM
 Really cool action! Big thanks for sharing it. Using transparent diffuse worked instantly when gameobject is chosen.
 
Title: Re: iTween FadeTo
Post by: TheDreamMaster on January 23, 2014, 06:39:56 PM
Indeed, it does not fade in.
Title: Re: iTween FadeTo
Post by: MrTopz on February 08, 2014, 04:40:41 PM
Great Playmaker + iTween action!

For those that are having problem on fading the object, just use a transparent shader and it will work.

Thanks for sharing this action with us!
Title: Re: iTween FadeTo
Post by: sxkx360 on March 04, 2014, 07:19:55 AM
   I´m not a shader wizard and I tried to incorporate this action with a mirror reflection shader which obviously didn´t work....
 I´m using a common mirror script and reflection shader http://wiki.unity3d.com/index.php?title=MirrorReflection2 (http://wiki.unity3d.com/index.php?title=MirrorReflection2) so if there is some tricky way to get it working it would be really useful for anyone.

 Any ideas?
Title: Re: iTween FadeTo
Post by: jeanfabre on March 04, 2014, 08:02:11 AM
Hi,

I personnally can't script shaders unfortunalty. Hopefully someone will step up, but you will have more chance asking the unity community.

bye,

 Jean
Title: Re: iTween FadeTo
Post by: swiftnz on August 31, 2014, 04:01:07 AM
Thanks Jernau for the action!

I made the Tooltip corrections as I agree with you it should say "end".
I also applied jeanfabre's recommendation of adding finish(); to the end of the OnEnter() section.
And as a bonus I also created the FadeFrom action, for people needing to fade in.

Both actions are zipped and attached to this post.

I tested both actions on my current project and they work fine for me.

Thanks,
swiftnz
Title: Re: iTween FadeTo
Post by: Boom7Games on October 05, 2014, 02:38:05 PM
I really dont understand how to use the alpha which is 0 by default and which shader you recommend for 2d. thx
Title: Re: iTween FadeTo
Post by: Twood on October 31, 2014, 02:16:08 PM
Nice action. Thanks for the share.

I really dont understand how to use the alpha which is 0 by default

You need to use a shader that supports transparency first. If it does then it works because it's fading to 0.
Title: Re: iTween FadeTo
Post by: cgidesign on July 10, 2015, 06:33:24 AM
hey sorry to dig up and old thread but this was exactly what i needed to fade an object in unity 5 + playmaker.

problem is, in unity it works fine! which is great (y) but when i build it using webgl,webplayer or standalone it doesnt work.

do you know why? or can you point me in the the right direction?
Title: Re: iTween FadeTo
Post by: dudebxl on July 10, 2015, 07:13:50 AM
Be careful with iTween, it's not the most optimized tween.. If you are going to tween a lot, you r better off using LeanTween or DoTween..

 ::)
Title: Re: iTween FadeTo
Post by: cgidesign on July 13, 2015, 07:24:33 AM
thanks dudebxl ill be sure to check it out now.
Title: Re: iTween FadeTo
Post by: Michaelb on September 03, 2015, 03:19:35 PM
Perfect , much appreciated.

Can someone please upload those 2 to the ecosystem?

Thank you advance

Michael.