示例#1
0
 public void ClearTags()
 {
     foreach (var t in Tags)
     {
         MultiTags.RemoveFromIndex(gameObject, t);
     }
     Tags = new string[0];
 }
示例#2
0
 void Awake()
 {
     //UnityEngine.Debug.Log(string.Format("DEFAULT TAGS: {0}", this.fieldDefaults.Count));
     //UnityEngine.Debug.Log(string.Format("AWAKE: {0} {1}", gameObject, MultiTags.SerializeTags(this.Tags)));
     foreach (var tag in this.Tags)
     {
         MultiTags.AddToIndex(gameObject, tag);
     }
 }
示例#3
0
 /// <summary>
 /// Determines if has all the specified multitags tags.
 /// </summary>
 /// <returns><c>true</c> if has all the specified multitags tags; otherwise, <c>false</c>.</returns>
 /// <param name="multitags">Multitags.</param>
 /// <param name="tags">Tags.</param>
 public static bool HasAll(MultiTags multitags, string[] tags)
 {
     foreach (var tag in tags)
     {
         if (!multitags.Tags.Any(t => MultiTags.TagsEqual(tag, t)))
         {
             return(false);
         }
     }
     return(true);
 }
示例#4
0
        public void AddTag(string tag)
        {
            if (HasTag(tag))
            {
                return;
            }

            var newTagArray = new string[Tags.Length + 1];

            Tags.CopyTo(newTagArray, 0);
            newTagArray[newTagArray.Length - 1] = tag;
            Tags = newTagArray;

            MultiTags.AddToIndex(gameObject, tag);
        }
示例#5
0
        void Recycled()
        {
            //UnityEngine.Debug.Log(string.Format("RECYCLED1: {0} {1}", gameObject, MultiTags.SerializeTags(this.Tags)));

            // First clear existing tags so they are removed from the index.
            this.ClearTags();

            // Add the default tags back to the index.
            foreach (var tag in this.Tags)
            {
                MultiTags.AddToIndex(gameObject, tag);
            }

            //UnityEngine.Debug.Log(string.Format("RECYCLED2: {0} {1}", gameObject, MultiTags.SerializeTags(this.Tags)));

            //ResetState();
        }
示例#6
0
        /// <summary>
        /// Finds the game objects that match the supplied tag filters.
        /// </summary>
        /// <returns>The game objects with tags.</returns>
        /// <param name="require">Require.</param>
        /// <param name="include">Include.</param>
        /// <param name="exclude">Exclude.</param>
        public static IList <GameObject> FindGameObjectsWithTags(IEnumerable <string> require, IEnumerable <string> include, IEnumerable <string> exclude)
        {
            // Get source collection containing objects with any "required" or "included" tags
            var sourceTags = new List <string>();

            sourceTags.AddRange(require);
            sourceTags.AddRange(include);
            var source = new HashSet <GameObject>();

            foreach (var tag in sourceTags)
            {
                foreach (var go in MultiTags.FindGameObjectsWithTag(tag))
                {
                    source.Add(go);
                }
            }

            return(FindGameObjectsWithTags(source, require, include, exclude));
        }
示例#7
0
        /// <summary>
        /// Finds the game objects in <paramref name="source"/> that match the supplied tag filters.
        /// </summary>
        /// <returns>The game objects with tags.</returns>
        /// <param name="source">Source.</param>
        /// <param name="require">Require.</param>
        /// <param name="include">Include.</param>
        /// <param name="exclude">Exclude.</param>
        public static IList <GameObject> FindGameObjectsWithTags(IEnumerable <GameObject> source, IEnumerable <string> require, IEnumerable <string> include, IEnumerable <string> exclude)
        {
            var filtered = new List <GameObject>();

            foreach (var go in source)
            {
                var multitags = go.GetComponent <MultiTags>();

                if (multitags == null)
                {
                    //Debug.LogWarning(string.Format("GameObject {0} did not have a MultiTags component", go));
                    continue;
                }

                // If gameobject has any of the "exclude" tags, discard it.
                if (exclude.Any() && MultiTags.HasAny(multitags, exclude.ToArray()))
                {
                    continue;
                }

                // If gameobject does not have all of the "require" tags, discard it.
                if (require.Any() && !MultiTags.HasAll(multitags, require.ToArray()))
                {
                    continue;
                }

                // If gameobject does not have any of the "include" tags, discard it.
                if (include.Any() && !MultiTags.HasAny(multitags, include.ToArray()))
                {
                    continue;
                }

                filtered.Add(go);
            }

            return(filtered);
        }
示例#8
0
 public bool HasAll(string[] tags)
 {
     return(MultiTags.HasAll(this, tags));
 }
示例#9
0
 public bool HasTag(string tag)
 {
     return(Tags.Any(t => MultiTags.TagsEqual(t, tag)));
 }
示例#10
0
 public void RemoveTag(string tag)
 {
     Tags = Tags.Where(t => !MultiTags.TagsEqual(t, tag)).ToArray();
     MultiTags.RemoveFromIndex(gameObject, tag);
 }