/// <summary> /// Check if the tag name is valid. /// </summary> private void CheckName() { // If the new tag name entered contains the tag separator, indicate it and refuse to create the tag if (tagName.Contains(MultiTags.TAG_SEPARATOR)) { doesNameContainSeparator = true; doesNameAlreadyExist = false; isNameEmpty = false; SetBigSize(); } else if (doesNameContainSeparator) { doesNameContainSeparator = false; SetSmallSize(); } // If a tag with the same name already exist, indicate it and refuse to create the tag if (MultiTagsUtility.GetUnityTags().Contains(tagName)) { doesNameAlreadyExist = true; isNameEmpty = false; SetBigSize(); } else if (doesNameAlreadyExist) { doesNameAlreadyExist = false; SetSmallSize(); } // If the name entered is empty, indicate it and refuse to create the tag if (string.IsNullOrEmpty(tagName.Trim())) { isNameEmpty = true; SetBigSize(); } else if (isNameEmpty) { isNameEmpty = false; SetSmallSize(); } }
/// <summary> /// Connect this project Unity tags with the tags asset to create missing ones on both of them. /// </summary> private void ConnectProjectTags() { List <string> _projectTags = MultiTagsUtility.GetUnityTags().ToList(); List <string> _projectMultiTags = _projectTags.SelectMany(t => t.Split(MultiTags.TAG_SEPARATOR)).Distinct().ToList(); string[] _referenceTags = tagsSO.CustomTags.TagNames; string[] _referenceUnityTags = tagsSO.UnityBuiltInTags.TagNames; // Adds each tag of this scriptable object to the project in not having them yet foreach (string _tag in _referenceTags) { if (!_projectTags.Contains(_tag)) { MultiTagsUtility.CreateUnityTag(_tag); } else { _projectTags.Remove(_tag); } if (_projectMultiTags.Contains(_tag)) { _projectMultiTags.Remove(_tag); } } // Adds all tags of this project this object doesn't have to it foreach (string _tag in _projectMultiTags) { if (MultiTags.BuiltInTagsNames.Contains(_tag)) { if (!_referenceUnityTags.Contains(_tag)) { tagsSO.UnityBuiltInTags.AddTag(new Tag(_tag)); } } else { tagsSO.CustomTags.AddTag(new Tag(_tag)); } } // Saves the asset EditorUtility.SetDirty(tagsSO); }