Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started 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!
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
));
}
}
}
-
Worked perfectly for me. Many thanks for the share, much appreciated!
-
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
-
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?
-
your shader have alpha value property?
-
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 :/
-
This works with a GUI Texture object as well.
I wonder if it's possible to fade in with this action as well?
-
I'm new on Playmaker and couldn't figure it out. May anyone help? Maybe make a video?
-
wow nice share. is it only for fade out?
i cannot fade in with this
-
Really cool action! Big thanks for sharing it. Using transparent diffuse worked instantly when gameobject is chosen.
-
Indeed, it does not fade in.
-
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!
-
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?
-
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
-
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
-
I really dont understand how to use the alpha which is 0 by default and which shader you recommend for 2d. thx
-
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.
-
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?
-
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..
::)
-
thanks dudebxl ill be sure to check it out now.
-
Perfect , much appreciated.
Can someone please upload those 2 to the ecosystem?
Thank you advance
Michael.