namespace Zinnia.Utility { using System.Text.RegularExpressions; using UnityEditor; /// /// Extension methods for . /// public static class SerializedPropertyExtensions { /// /// Matches the index found in if it exists. /// private static readonly Regex indexRegex = new Regex(@"\.Array\.data\[(?'index'\d*)\]$", RegexOptions.Compiled); /// /// The index found in if it exists. /// /// The property to search on. /// The index if found, otherwise . public static int? TryGetIndex(this SerializedProperty property) { Match match = indexRegex.Match(property.propertyPath); return match.Success ? int.Parse(match.Groups["index"].Value) : (int?)null; } } }