示例#1
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);
        }
示例#2
0
 public bool HasAll(string[] tags)
 {
     return(MultiTags.HasAll(this, tags));
 }