Beispiel #1
0
 /// <summary>
 /// Runs a query on the current state of gameobjects with MultiTagComponent.
 /// </summary>
 /// <param name="multiTagFilter"></param>
 /// <returns>Returns the first index</returns>
 public static GameObject QuerySingle(MultiTagFilter multiTagFilter)
 {
     return(RunQuery(multiTagFilter)[0]);
 }
Beispiel #2
0
        private static List <GameObject> RunQuery(MultiTagFilter multiTagFilter)
        {
            List <GameObject> result = null;

            var any  = multiTagFilter.Any;
            var all  = multiTagFilter.All;
            var none = multiTagFilter.None;

            var resultHash = new HashSet <GameObject>();

            if (any != null)
            {
                for (int i = 0; i < any.Length; i++)
                {
                    var key = any[i];
                    if (MtDict.ContainsKey(key))
                    {
                        var tempResult = MtDict[key];

                        if (tempResult != null && tempResult.Count != 0)
                        {
                            resultHash.UnionWith(tempResult);
                        }
                    }
                }
                result = resultHash.ToList();
            }

            if (all != null)
            {
                for (int i = 0; i < all.Length; i++)
                {
                    var key = all[i];
                    if (MtDict.ContainsKey(key))
                    {
                        var tempResult = MtDict[key];

                        if (tempResult != null && tempResult.Count != 0)
                        {
                            result = result == null?tempResult.ToList() : tempResult.Intersect(result).ToList();
                        }
                    }
                }
            }

            if (none != null)
            {
                if (result == null)
                {
                    if (resultHash.Count > 0)
                    {
                        resultHash.Clear();
                    }

                    foreach (var dict in MtDict)
                    {
                        var list = dict.Value;
                        resultHash.UnionWith(list);
                    }
                    result = resultHash.ToList();
                }

                for (int i = 0; i < none.Length; i++)
                {
                    var key = none[i];
                    if (MtDict.ContainsKey(key))
                    {
                        var toRemove = MtDict[key];

                        if (toRemove != null && toRemove.Count != 0)
                        {
                            var theSet = new HashSet <GameObject>(toRemove);
                            result.RemoveAll(item => theSet.Contains(item));
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #3
0
 /// <summary>
 /// Runs a query on the current state of gameobjects with MultiTagComponent.
 /// </summary>
 /// <param name="multiTagFilter">Query parameters</param>
 /// <returns>A shallow List of GameObjects</returns>
 public static List <GameObject> QueryMultiple(MultiTagFilter multiTagFilter)
 {
     //Creates a shallow copy
     return(RunQuery(multiTagFilter).ToList());
 }