Version: 2023.2

SearchExpression.TryConvertToDouble

切换到手册
public static bool TryConvertToDouble (Search.SearchItem item, out double value, string selector);

参数

item SearchItem to extract the value from.
value Resulting value.
selector Selector use to access an item value. If null, we will use the internal item value.

返回

bool Returns true if we were able to select the value and convert it to a double.

描述

Resolve a selector on an item and try to convert the selected value to a double.

[Description("Returns asset paths corresponding to a list of instance ids")]
[SearchExpressionEvaluator("IdsToPaths", SearchExpressionEvaluationHints.ThreadNotSupported, SearchExpressionType.Iterable)]
public static IEnumerable<SearchItem> IdsToPath(SearchExpressionContext c)
{
    foreach (var idItem in c.args[0].Execute(c))
    {
        if (SearchExpression.TryConvertToDouble(idItem, out var idNum))
        {
            var id = (int)idNum;
            var path = AssetDatabase.GetAssetPath(id);
            if (!string.IsNullOrEmpty(path))
            {
                yield return SearchExpression.CreateItem(path, c.ResolveAlias("asset path"));
            }
        }
    }
}