/// <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 = MultiTags.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 = MultiTags.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> /// Registers a GameObject into the field <see cref="objectsTags"/>. /// </summary> /// <param name="_object">GameObject to register.</param> private void RegisterObject(GameObject _object) { int _id = _object.GetInstanceID(); if (!TDS_LevelManager.Instance.ObjectsTags.ContainsKey(_id)) { TDS_LevelManager.Instance.ObjectsTags.Add(_id, new Tags(MultiTags.GetTags(_object.tag.Split(MultiTags.TAG_SEPARATOR)))); } }
/// <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) { #if UNITY_EDITOR if (!Application.isPlaying) { return(MultiTags.GetTags(_go.GetTagNames())); } #endif return(MultiTags.TagsAsset.GetObjectTags(_go)); }
/// <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(MultiTags.GetTags(_go.GetTagNames())); }