Files
beyond/Assets/ThirdParty/PlayMaker/Actions/UI/UiInputFieldSetCaretBlinkRate.cs
2024-11-20 15:21:28 +01:00

76 lines
1.6 KiB
C#

// (c) Copyright HutongGames, LLC 2010-2018. All rights reserved.
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.UI)]
[Tooltip("Sets the caret's blink rate of a UI InputField component.")]
public class UiInputFieldSetCaretBlinkRate : ComponentAction<UnityEngine.UI.InputField>
{
[RequiredField]
[CheckForComponent(typeof(UnityEngine.UI.InputField))]
[Tooltip("The GameObject with the UI InputField component.")]
public FsmOwnerDefault gameObject;
[RequiredField]
[Tooltip("The caret's blink rate for the UI InputField component.")]
public FsmInt caretBlinkRate;
[Tooltip("Deactivate when exiting this state.")]
public FsmBool resetOnExit;
[Tooltip("Repeats every frame")]
public bool everyFrame;
private UnityEngine.UI.InputField inputField;
private float originalValue;
public override void Reset()
{
gameObject = null;
caretBlinkRate = null;
resetOnExit = null;
everyFrame = false;
}
public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (UpdateCache(go))
{
inputField = cachedComponent;
}
originalValue = inputField.caretBlinkRate;
DoSetValue();
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
DoSetValue();
}
private void DoSetValue()
{
if (inputField != null)
{
inputField.caretBlinkRate = caretBlinkRate.Value;
}
}
public override void OnExit()
{
if (inputField == null) return;
if (resetOnExit.Value)
{
inputField.caretBlinkRate = originalValue;
}
}
}
}