Collection Contains Text#
Collections / Collection Contains Text
Can Read
Cannot Write
Description#
Returns True if any item of the collection matches the specified text
Note
Every item is read as text before comparing it. Objects are read as their name
Parameters#
| Name | Description |
|---|---|
| Collection | The collection whose items are searched |
| Value | The text every item is compared against |
| Ignore Case | Whether upper and lower case characters are considered the same |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Collection Contains Text")]
[Category("Collections/Contains Text")]
[Description("Returns True if any item of the collection matches the specified text")]
[Image(typeof(IconStack), ColorTheme.Type.Teal, typeof(BadgeString))]
[Parameter("Collection", "The collection whose items are searched")]
[Parameter("Value", "The text every item is compared against")]
[Parameter("Ignore Case", "Whether upper and lower case characters are considered the same")]
[Note("Every item is read as text before comparing it. Objects are read as their name")]
[Keywords("Has", "Includes", "Find", "Search", "Any", "List", "Array")]
[Serializable]
public class TypeBoolCollectionContains : TypeBool
{
[SerializeField] private GetCollection m_Collection = new GetCollection();
[SerializeField] private GetString m_Value = new GetString();
[SerializeField] private GetBool m_IgnoreCase = new GetBool(false);
public override bool Get(Args args)
{
using Args scoped = Args.Get(args);
int count = this.m_Collection.Capture(scoped);
if (count == 0) return false;
string value = this.m_Value.Get(args);
StringComparison comparison = this.m_IgnoreCase.Get(args)
? StringComparison.OrdinalIgnoreCase
: StringComparison.Ordinal;
for (int i = 0; i < count; ++i)
{
if (!ArgsCollectionParameters.TryGetItem(this.m_Collection, scoped, i, out string item)) continue;
if (string.Equals(item, value, comparison)) return true;
}
return false;
}
public override string ToString()
{
return $"{this.m_Collection} contains {this.m_Value}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}