FANDOM


This custom Action allows you to change a UI Text component's label. Note that normally you'll want to link a UI Text component to the Menu Manager as a Label element, but this method allows you to control a UI Text without doing so.

The Text and Label fields can both be overridden with ActionList parameters.

using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{

[System.Serializable]
public class ActionTextLabel : Action
{

public Text text;
public int textConstantID = 0;
public int textParameterID = -1;

public string newLabel;
public int newLabelParameterID = -1;


public ActionTextLabel ()
{
this.isDisplayed = true;
category = ActionCategory.Menu;
title = "Update text label";
description = "Changes the contents of a UI Text box.";
}


public override void AssignValues (List<ActionParameter> parameters)
{
newLabel = AssignString (parameters, newLabelParameterID, newLabel);
text = AssignFile <Text> (parameters, textParameterID, textConstantID, text);
}


override public float Run ()
{
if (text != null)
{
text.text = newLabel;
}

return 0f;
}


#if UNITY_EDITOR

override public void ShowGUI (List<ActionParameter> parameters)
{
textParameterID = Action.ChooseParameterGUI ("Text component:", parameters, textParameterID, ParameterType.GameObject);
if (textParameterID >= 0)
{
textConstantID = 0;
text = null;
}
else
{
text = (Text) EditorGUILayout.ObjectField ("Text component:", text, typeof (Text), true);

textConstantID = FieldToID (text, textConstantID);
text = IDToField (text, textConstantID, false);
}

newLabelParameterID = Action.ChooseParameterGUI ("FSM to call (optional):", parameters, newLabelParameterID, ParameterType.String);
if (newLabelParameterID < 0)
{
newLabel = EditorGUILayout.TextField ("New label:", newLabel);
}

AfterRunningOption ();
}


#endif

}

}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.