Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: FRickReich on February 04, 2014, 08:13:15 AM

Title: Translate To Bar Value (good for NGUI)
Post by: FRickReich on February 04, 2014, 08:13:15 AM
Hey there,

i found it a bit annoying to always create 2 float operators to render out "width = hp / max_hp * max_width" to convert a value to the length of a bar in NGUI so i created this little playmaker action, hope you can make some good use of it!

(https://dl-web.dropbox.com/get/Public/Playmaker_TranslateToBar1.png?_subject_uid=2863238&w=AAAsbaRvWyPMsnpgvIsQb8nYPlmQ-KUwLDd18uTbxG7wtw)

(https://dl-web.dropbox.com/get/Public/Playmaker_TranslateToBar2.png?_subject_uid=2863238&w=AACeyYNdYU7KwQkrUIa1gOIHQTX8IIcl7lgaTz6ViH2R0g)

Code: [Select]
// (c) 2014 F. Rick Reich.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Custom")]
[Tooltip("Translates a float to the width of a Progressbar (Usable for eg. Healthbars).")]
public class TranslateToBarValue : FsmStateAction
{

[RequiredField]
public FsmFloat CurrentValue;

[RequiredField]
public FsmFloat MaxValue;

[RequiredField]
public FsmFloat MaxBarWidth;

public FsmFloat Result;

public bool everyFrame;

public override void Reset()
{
CurrentValue = null;
MaxValue = null;
MaxBarWidth = 1.0f;
Result = null;
everyFrame = false;
}

public override void OnEnter()
{

Result.Value = CurrentValue.Value / MaxValue.Value * MaxBarWidth.Value;

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
Result.Value = CurrentValue.Value / MaxValue.Value * MaxBarWidth.Value;
}
}
}
Title: Re: Translate To Bar Value (good for NGUI)
Post by: jeanfabre on February 04, 2014, 12:46:28 PM
Hi,

 Nice!  It's actually very similar to the floatRemap custom action ( or better known as cross multiplication)

http://hutonggames.com/playmakerforum/index.php?topic=5122.msg24311#msg24311


Your action is more obvious to use, and that's very good. tho, if you you find yourself having to remap floats in a more complex set of ranges, FloatRemap will be handy.

bye,

 Jean
Title: Re: Translate To Bar Value (good for NGUI)
Post by: FRickReich on February 04, 2014, 06:14:30 PM
Hey Jean, didn't know about your Action right there  :-\, but i can see the similarities.

I think yours can be used for anything around cross-multiplications while mine is, even if usable for the same thing, more specifically for things like a Healthbar.

- Rick.