playMaker

Author Topic: iTween FadeTo  (Read 20654 times)

Jernau

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
iTween FadeTo
« on: June 16, 2012, 02:00:30 PM »
I was having trouble figuring out how to fade a GameObject to invisible. So I added the iTween 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 
                              ));
}
}
}

smiffy

  • Junior Playmaker
  • **
  • Posts: 54
    • View Profile
Re: iTween FadeTo
« Reply #1 on: June 27, 2012, 03:01:35 PM »
Worked perfectly for me. Many thanks for the share, much appreciated!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14238
  • Official Playmaker Support
    • View Profile
Re: iTween FadeTo
« Reply #2 on: June 27, 2012, 10:35:22 PM »
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

Mayhem

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Re: iTween FadeTo
« Reply #3 on: March 07, 2013, 06: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?

3d_Artist1987

  • Beta Group
  • Full Member
  • *
  • Posts: 157
    • View Profile
Re: iTween FadeTo
« Reply #4 on: March 07, 2013, 07:07:30 AM »
your shader have alpha value property?

Mayhem

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Re: iTween FadeTo
« Reply #5 on: March 07, 2013, 07: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 :/

tankun

  • Playmaker Newbie
  • *
  • Posts: 26
    • View Profile
Re: iTween FadeTo
« Reply #6 on: June 06, 2013, 05: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?

ExprSt

  • Playmaker Newbie
  • *
  • Posts: 20
    • View Profile
Re: iTween FadeTo
« Reply #7 on: November 27, 2013, 02:09:37 PM »
I'm new on Playmaker and couldn't figure it out. May anyone help? Maybe make a video?

johanesnw

  • Playmaker Newbie
  • *
  • Posts: 26
    • View Profile
Re: iTween FadeTo
« Reply #8 on: January 16, 2014, 02:25:35 AM »
wow nice share. is it only for fade out?
i cannot fade in with this

sxkx360

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: iTween FadeTo
« Reply #9 on: January 17, 2014, 05:37:59 AM »
 Really cool action! Big thanks for sharing it. Using transparent diffuse worked instantly when gameobject is chosen.
 

TheDreamMaster

  • Playmaker Newbie
  • *
  • Posts: 11
    • View Profile
Re: iTween FadeTo
« Reply #10 on: January 23, 2014, 04:39:56 PM »
Indeed, it does not fade in.

MrTopz

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Re: iTween FadeTo
« Reply #11 on: February 08, 2014, 02: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!

sxkx360

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: iTween FadeTo
« Reply #12 on: March 04, 2014, 05: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 so if there is some tricky way to get it working it would be really useful for anyone.

 Any ideas?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14238
  • Official Playmaker Support
    • View Profile
Re: iTween FadeTo
« Reply #13 on: March 04, 2014, 06: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

swiftnz

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
Re: iTween FadeTo
« Reply #14 on: August 31, 2014, 01: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