Skip to content

Instantly share code, notes, and snippets.

@TarasOsiris
Created November 27, 2014 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TarasOsiris/28eb0084e5c1437a7b27 to your computer and use it in GitHub Desktop.
Save TarasOsiris/28eb0084e5c1437a7b27 to your computer and use it in GitHub Desktop.
Updates NGUI Label with provided parameters. Playmaker Action
using UnityEngine;
using HutongGames.PlayMaker;
[ActionCategory("NGUI")]
[HutongGames.PlayMaker.Tooltip("Updates NGUI Label with provided parameters")]
public class NGUI_UpdateLabel : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(UILabel))]
[HutongGames.PlayMaker.Tooltip("Game Object to update.")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.FsmString)]
[HutongGames.PlayMaker.Tooltip("UILabel text to set")]
public FsmString labelText;
[UIHint(UIHint.FsmColor)]
[HutongGames.PlayMaker.Tooltip("The color to set.")]
public FsmColor labelColor;
private UILabel _label;
public override void Reset()
{
gameObject = null;
labelText = string.Empty;
labelColor = Color.white;
}
public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
Finish();
return;
}
_label = go.GetComponent<UILabel>();
if (_label == null)
{
LogWarning("Missing UILabel component on GameObject: [" + go.name + "]");
Finish();
return;
}
_label.text = labelText.Value;
_label.color = labelColor.Value;
Finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment