static string GetSanitizedAndUniqueAddress(SerializedProperty mappingsProp, int mappingIndex, string address) { // Sanitize OscAddress.Sanitize(ref address); // Gather all addresses, excluding the one from the mapping we are messing with (if any). List <string> addresses = new List <string>(); for (int m = 0; m < mappingsProp.arraySize; m++) { if (m != mappingIndex) { addresses.Add(mappingsProp.GetArrayElementAtIndex(m).FindPropertyRelative(mappingAddressFieldName).stringValue); } } // Make unique if (!addresses.Contains(address)) { return(address); } string addressWithoutNumber = address.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }); for (int i = 1; ; i++) { string candidateAddress = addressWithoutNumber + i; if (!addresses.Contains(candidateAddress)) { return(candidateAddress); } } }
public bool IsMatching(string address) { if (hasSpecialPattern) { return(OscAddress.IsMatching(address, _address)); } return(string.Compare(address, _address) == 0); }