// NOTE: Most of this comes from Virt-A-Mate's implementation. public static string CreateUID(this SuperController sc, string source) { var uids = new HashSet <string>(sc.GetAtomUIDs()); var hashIndex = source.LastIndexOf('#'); var startAt = 0; if (hashIndex == -1) { if (!uids.Contains(source)) { return(source); } source += "#"; startAt = 2; } else { if (int.TryParse(source.Substring(hashIndex + 1), out startAt)) { startAt++; } else { startAt = 2; } source = source.Substring(0, hashIndex + 1); } for (var i = startAt; i < 1000; i++) { var uid = source + i; if (!uids.Contains(uid)) { return(uid); } } return(source + Guid.NewGuid()); }