Hi,
Here we go:
As you said, take this as a template, making other regex calls will only differs a little bit, some regex will return a string for example.
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
using System.Text.RegularExpressions;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Regex")]
[Tooltip("Performs a IsMatch on a String Variable.")]
public class RegexIsMatch: FsmStateAction
{
[RequiredField]
public FsmString stringVariable;
[RequiredField]
public FsmString regexExpression;
[UIHint(UIHint.Variable)]
public FsmBool storeResult;
public FsmEvent isMatchEvent;
public FsmEvent isNotMatchEvent;
public override void Reset()
{
stringVariable = null;
regexExpression = null;
storeResult = null;
isMatchEvent = null;
isNotMatchEvent = null;
}
public override void OnEnter()
{
DoIsMatch();
Finish();
}
void DoIsMatch()
{
if (stringVariable == null) return;
if (regexExpression == null) return;
bool result = Regex.IsMatch(stringVariable.Value,@regexExpression.Value);
storeResult.Value = result;
if (result && isMatchEvent !=null)
{
Fsm.Event(isMatchEvent);
}else if ( result == false && isNotMatchEvent != null){
Fsm.Event(isNotMatchEvent);
}
}
}
}
If you need regex that returns several strings, then I suggest you use ArrayMaker for this, I can give you a template action for this too ( that would be great actually, running a reg ex within an array of string and store the results in another array).
Bye,
Jean