50 lines
980 B
C#
50 lines
980 B
C#
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.
|
|
|
|
using UnityEngine;
|
|
|
|
namespace HutongGames.PlayMaker.Actions
|
|
{
|
|
[ActionCategory(ActionCategory.Vector2)]
|
|
[Tooltip("Clamps the Magnitude of Vector2 Variable.")]
|
|
public class Vector2ClampMagnitude : FsmStateAction
|
|
{
|
|
[RequiredField]
|
|
[UIHint(UIHint.Variable)]
|
|
[Tooltip("The Vector2")]
|
|
public FsmVector2 vector2Variable;
|
|
|
|
[RequiredField]
|
|
[Tooltip("The maximum Magnitude")]
|
|
public FsmFloat maxLength;
|
|
|
|
[Tooltip("Repeat every frame")]
|
|
public bool everyFrame;
|
|
|
|
public override void Reset()
|
|
{
|
|
vector2Variable = null;
|
|
maxLength = null;
|
|
everyFrame = false;
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
DoVector2ClampMagnitude();
|
|
|
|
if (!everyFrame)
|
|
Finish();
|
|
}
|
|
|
|
public override void OnUpdate()
|
|
{
|
|
DoVector2ClampMagnitude();
|
|
}
|
|
|
|
void DoVector2ClampMagnitude()
|
|
{
|
|
vector2Variable.Value = Vector2.ClampMagnitude(vector2Variable.Value, maxLength.Value);
|
|
}
|
|
}
|
|
}
|
|
|