-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTranslateToBarValue.cs
50 lines (38 loc) · 936 Bytes
/
TranslateToBarValue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2014 F. Rick Reich.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Advanced Actions")]
[Tooltip("Translates a float to the width of a Progressbar (Usable for eg. Healthbars in NGUI).")]
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;
}
}
}