playMaker

Author Topic: [iTween Action] Tween Alpha of Object  (Read 2272 times)

alabatusa

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
[iTween Action] Tween Alpha of Object
« on: May 28, 2014, 09:47:45 PM »
Hi All,

My first "working" custom action. Basically used already in place iTween actions to generate an action which tweens the alpha of an object over time.

E.g where this could be used in a game, is say a coin pick up, rather than disappearing instantly on pick up fade out over desired time.

Hope it helps someone.
Note: For this to work the object material renderer must support transparency.

Code: [Select]
using UnityEngine;
namespace HutongGames.PlayMaker.Actions

{
[ActionCategory("iTween")]
[Tooltip("Varies GameObject's Alpha over time by fading.")]
public class iTweenAlphaBy: 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;

[RequiredField]
[Tooltip("A Alpha value that GameObject will tween to.")]
public FsmFloat Alpha;
[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("Can be used instead of time to allow animation based on speed. When you define speed the time variable is ignored.")]
public FsmFloat speed;
[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};
time = 1f;
delay = 0f;
loopType = iTween.LoopType.none;
Alpha = new FsmFloat { UseVariable = true };
speed = new FsmFloat { UseVariable = true };
}

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;

// init position

float amount = 0f;
if (Alpha.IsNone) {

} else {
amount = Alpha.Value;
}

itweenType = "alpha";
iTween.FadeTo(go, iTween.Hash(
"amount", amount,
"name", id.IsNone ? "" : id.Value,
speed.IsNone ? "time" : "speed", speed.IsNone ? time.IsNone ? 1f : time.Value : speed.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 
));
}
}

}

zorranco

  • Playmaker Newbie
  • *
  • Posts: 44
    • View Profile
Re: [iTween Action] Tween Alpha of Object
« Reply #1 on: October 01, 2015, 03:33:14 AM »
Sorry for bump, but this action is really useful since I have never seen a similar one.

Problem is in Unity 5 if you put alpha to zero, it works flawlessly but any other value results in material getting a weird random tint...I think it is related to standard shader in Unity 5 (probably you tested it in Unity 4 without problem).

Any chance to adapt this custom action for the new standard shader in U5?
« Last Edit: October 01, 2015, 03:56:07 AM by zorranco »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: [iTween Action] Tween Alpha of Object
« Reply #2 on: October 01, 2015, 03:58:36 AM »
Fyi,

DoTween actions has fade (material,etc) and it works for unity 5.

Just saying......

zorranco

  • Playmaker Newbie
  • *
  • Posts: 44
    • View Profile
Re: [iTween Action] Tween Alpha of Object
« Reply #3 on: October 01, 2015, 05:19:38 AM »
Double post, sry
« Last Edit: October 01, 2015, 05:44:14 AM by zorranco »

zorranco

  • Playmaker Newbie
  • *
  • Posts: 44
    • View Profile
Re: [iTween Action] Tween Alpha of Object
« Reply #4 on: October 01, 2015, 05:36:18 AM »
Very useful!

Now trying to guess what is the property to launch DOTween fade :)

Enable and autoPlay properties does not launch the tweener


PD: I've downloaded DOTween actions for playmaker but Fade action produces same result, weird colors UU'
« Last Edit: October 01, 2015, 06:01:01 AM by zorranco »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: [iTween Action] Tween Alpha of Object
« Reply #5 on: October 01, 2015, 06:12:37 AM »
ok strange..

did you fill out properly the 'Material fade extra' section? Make sure you name it properly like for tint color u need to input: _TintColor

I just tested and it works..

better reply at : http://hutonggames.com/playmakerforum/index.php?topic=10303.msg53260;topicseen#msg53260
« Last Edit: October 01, 2015, 06:24:42 AM by dudebxl »

zorranco

  • Playmaker Newbie
  • *
  • Posts: 44
    • View Profile
Re: [iTween Action] Tween Alpha of Object
« Reply #6 on: October 01, 2015, 07:54:29 AM »
I answered you in the DOTween thread.

Now everything works as expected, thanks!