namespace Zinnia.Rule
{
using System.Text.RegularExpressions;
using UnityEngine;
using Zinnia.Data.Collection.List;
using Zinnia.Extension;
///
/// Determines whether a with a component contains a string that matches a specified pattern.
///
public class StringInListRule : GameObjectRule
{
[Tooltip("The regular expression pattern to match against a string contained in the StringObservableList.")]
[SerializeField]
private string inListPattern;
///
/// The regular expression pattern to match against a string contained in the .
///
public string InListPattern
{
get
{
return inListPattern;
}
set
{
inListPattern = value;
}
}
///
protected override bool Accepts(GameObject targetGameObject)
{
StringObservableList list = targetGameObject.TryGetComponent();
if (list != null)
{
foreach (string element in list.NonSubscribableElements)
{
if (Regex.IsMatch(element, InListPattern))
{
return true;
}
}
}
return false;
}
}
}