/// <summary> /// Adds multiple new tags to the object. /// </summary> /// <param name="_tags">Name of the tags to add.</param> public void AddTags(string[] _tags) { // If this object already contains a tag with the same name, do not add it. string[] _tagNames = TagNames; _tags = _tags.Where(t => !_tagNames.Contains(t)).ToArray(); if (_tags.Length == 0) { return; } Tag[] _newTags = new Tag[ObjectTags.Length + _tags.Length]; Tag[] _existingTags = MultiTagsUtil.GetTags(_tags); for (int _i = 0; _i < ObjectTags.Length; _i++) { _newTags[_i] = ObjectTags[_i]; } for (int _i = 0; _i < _existingTags.Length; _i++) { _newTags[ObjectTags.Length + _i] = _existingTags[_i]; } for (int _i = _existingTags.Length; _i < _tags.Length; _i++) { _newTags[ObjectTags.Length + _i] = new Tag(_tags[_i]); } ObjectTags = _newTags; Sort(); }
/// <summary> /// Get tags of editing object(s). /// If editing multiple objects and they have different tags, /// get only tags in common. /// </summary> private void GetObjectsTags() { // If editing multiple objects and they do not have the same tag, // get tags in common between them if (serializedObject.isEditingMultipleObjects) { string[][] _objectTags = targetGO.Select(t => t.GetTagNames()).ToArray(); string[] _tagsInCommon = _objectTags.Aggregate((previousList, nextList) => previousList.Intersect(nextList).ToArray()); editingTags = MultiTagsUtil.GetTags(_tagsInCommon); lastTags = targetGO.Select(g => g.tag).ToArray(); haveTargetsDifferentTags = _objectTags.Any(t => !Enumerable.SequenceEqual(t, _tagsInCommon)); } // Else, just get tags of the first editing object else { // Get editing object tags lastTags = new string[1] { targetGO[0].tag }; editingTags = targetGO[0].GetTags(); haveTargetsDifferentTags = false; } }
/// <summary> /// Get a Tag objects from all this game object tags. /// </summary> /// <param name="_go">Game object to get tags from.</param> /// <returns>Returns a Tags object from all this game object tags.</returns> public static Tag[] GetTags(this GameObject _go) { return(MultiTagsUtil.GetTags(_go.GetTagNames())); }
/// <summary> /// Adds a new tag to the object. /// </summary> /// <param name="_tag">Name of the tag to add.</param> public void AddTag(string _tag) { Tag _toAdd = MultiTagsUtil.GetTag(_tag) ?? new Tag(_tag); AddTag(_toAdd); }