Yet another string regex action. This one, similar to String Regex Is Match, can do a true/false event based off the match, but it also stores the result of the match to another string variable instead of storing true/false to boolean.
[edit] You can now get it directly from the
EcosystemStringRegexMatchusing UnityEngine;
using System.Text.RegularExpressions;
namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.String)]
public class StringRegexMatch : FsmStateAction {
[RequiredField, UIHint(UIHint.Variable)]
public FsmString stringVariable;
public FsmString regex;
public RegexOptions[] options;
[UIHint(UIHint.Variable)]
public FsmString storeMatch;
[UIHint(UIHint.Variable)]
public FsmEvent trueEvent;
[UIHint(UIHint.Variable)]
public FsmEvent falseEvent;
public bool everyFrame;
public override void Reset() {
stringVariable = null;
regex = new FsmString { Value = "" };
options = new RegexOptions[0];
storeMatch = null;
trueEvent = null;
falseEvent = null;
everyFrame = false;
}
public override void OnEnter() {
DoAction();
if ( ! everyFrame ) {
Finish();
}
}
public override void OnUpdate() {
DoAction();
}
void DoAction() {
Match match = null;
if ( options.Length > 0 ) {
RegexOptions optionsBit = 0;
foreach ( RegexOptions option in options ) {
optionsBit |= option;
}
match = Regex.Match( stringVariable.Value, regex.Value, optionsBit );
} else {
match = Regex.Match( stringVariable.Value, regex.Value );
}
storeMatch.Value = match.Value;
if ( match.Success ) {
if ( trueEvent != null ) {
Fsm.Event( trueEvent );
}
} else {
if ( falseEvent != null ) {
Fsm.Event( falseEvent );
}
}
}
}
}
You can find my other String Regex actions as follows.
String Regex Is Match:
http://hutonggames.com/playmakerforum/index.php?topic=7005.0String Regex Replace:
http://hutonggames.com/playmakerforum/index.php?topic=7004.0