I wanted to use REGEX for my replacement usage so I created a String Regex Replace. Thought I'd go ahead and share it as it's a pretty generic and useful action.
[edit] It's now available directly on the
EcosystemStringRegexReplaceusing UnityEngine;
using System.Text.RegularExpressions;
namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.String)]
public class StringRegexReplace : FsmStateAction {
[RequiredField, UIHint(UIHint.Variable)]
public FsmString stringVariable;
public FsmString regex;
public FsmString with;
public RegexOptions[] options;
[RequiredField, UIHint(UIHint.Variable)]
public FsmString storeResult;
public bool everyFrame;
public override void Reset() {
stringVariable = null;
regex = new FsmString { Value = "" };
with = new FsmString { Value = "" };
options = new RegexOptions[0];
storeResult = null;
everyFrame = false;
}
public override void OnEnter() {
DoAction();
if ( ! everyFrame ) {
Finish();
}
}
public override void OnUpdate() {
DoAction();
}
void DoAction() {
if ( options.Length > 0 ) {
RegexOptions optionsBit = 0;
foreach ( RegexOptions option in options ) {
optionsBit |= option;
}
storeResult.Value = Regex.Replace( stringVariable.Value, regex.Value, with.Value, optionsBit );
} else {
storeResult.Value = Regex.Replace( stringVariable.Value, regex.Value, with.Value );
}
}
}
}
I'll probably be adding other regex actions as well such as Match. Anyway, hope others find as much use out of this as I have.