60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using System.Text.RegularExpressions;
|
|
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
|
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
|
using Opsive.GraphDesigner.Runtime.Variables;
|
|
using Opsive.Shared.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters.AI
|
|
{
|
|
[Category("SLS Utilities")]
|
|
[Description("Checks a string value against a specified condition.")]
|
|
public class CheckString : Conditional
|
|
{
|
|
public SharedVariable<string> targetString;
|
|
|
|
[Header("Full Match")]
|
|
public bool isFullMatch;
|
|
public string matchString;
|
|
|
|
[Header("Contains")]
|
|
public bool isContains;
|
|
public string containsString;
|
|
|
|
[Header("Regex Match")]
|
|
public bool isRegexMatch;
|
|
public string regexPattern;
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
string value = targetString.Value;
|
|
|
|
if (isFullMatch && value == matchString)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
if (isContains && value.Contains(containsString))
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
if (isRegexMatch)
|
|
{
|
|
try
|
|
{
|
|
if (Regex.IsMatch(value, regexPattern))
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError($"Regex pattern error: {e.Message}");
|
|
}
|
|
}
|
|
|
|
return TaskStatus.Failure;
|
|
}
|
|
}
|
|
} |