private static void GetSubstancesFromTag(string tag, SubstanceSet set, ISubstanceFilter filter)
        {
            while (!string.IsNullOrEmpty(tag) && !Equals(tag, "Untagged"))
            {
                int startMat = tag.IndexOf("m:");
                if (startMat == -1)
                {
                    return;
                }

                tag = tag.Substring(startMat + 2);
                int endMat = tag.IndexOf(' ');

                string substanceName = tag;
                if (endMat != -1)
                {
                    substanceName = tag.Substring(0, endMat);
                    tag           = tag.Substring(endMat + 1);
                }

                if (substanceName != "" && Instance.nameBasedSubstances.TryGetValue(substanceName, out Substance s))
                {
                    s.AddToSet(set, filter);
                }

                if (endMat == -1)
                {
                    break;
                }
            }
        }
 private void DelayedAddToSet(SubstanceSet set, ISubstanceFilter filter)
 {
     set.Add(this);
     foreach (var c in ChildSubstances)
     {
         c.AddToSet(set, filter);
     }
 }
 //Only temporarily
 public bool ExeAddToSet(SubstanceSet substanceSet)
 {
     if (Time.fixedTime < exeTime)
     {
         DelayedAddToSet(substanceSet, exeFilter);
         return(false);
     }
     return(true);
 }
Beispiel #4
0
 public bool ExeAddToSet(SubstanceSet substanceSet)
 {
     if (Time.fixedTime >= exeTime)
     {
         parent.DelayedAddToSet(substanceSet, filter);
         return(true);
     }
     return(false);
 }
Beispiel #5
0
 private void AddToSetP(SubstanceSet set, ISubstanceFilter filter)
 {
     if (Delay <= 0)
     {
         DelayedAddToSet(set, filter);
         return;
     }
     set.SubSetQuery.Add(new DelayedSubExecutable(Delay, this, filter));
 }
 private void AddToSetP(SubstanceSet set, ISubstanceFilter filter)
 {
     if (Delay <= 0)
     {
         DelayedAddToSet(set, filter);
         return;
     }
     exeTime   = Delay + Time.fixedTime;
     exeFilter = filter;
     set.SubSetQuery.Add(this);
 }
        public static void RetrieveSubstances(BoxCollider2D collider2D, SubstanceSet set, ISubstanceFilter filter, LayerMask layerMask, out bool touch)
        {
            List <Collider2D> colliders = new List <Collider2D>();

            collider2D.OverlapCollider(GetContactFilter(layerMask), colliders);
            //Debug.Log("Colliders: " + colliders.Count);
            touch = colliders.Count > 0;
            //Debug.Log("Colliders: " + colliders.Count);
            //if (touch)
            // Debug.Log("Touching: " + colliders[0].name);
            RetrieveSubstances(new Rect()
            {
                size = collider2D.size, center = collider2D.offset
            }.LocalToWorldRect(collider2D.transform), set, filter, colliders, GetContactFilter(layerMask));
        }
Beispiel #8
0
 public override void AddToSet(SubstanceSet set, ISubstanceFilter filter)
 {
     //if (set.Contains(this))
     //return;
     if (SubstanceSpecifier.Count == 0)
     {
         AddToSetHelper(set, filter);
         return;
     }
     foreach (var specifier in SubstanceSpecifier)
     {
         if (filter.IsValidSubstance(specifier))
         {
             AddToSetHelper(set, filter);
             return;
         }
     }
 }
        private static void RetrieveSubstances(Rect rect, SubstanceSet set, ISubstanceFilter filter, List <Collider2D> colliders, ContactFilter2D cf)
        {
            foreach (Collider2D collider in colliders)
            {
                if (collider.TryGetComponent <Tilemap>(out Tilemap tilemap))
                {
                    GetSubstancesFromTilemap(rect, tilemap, collider, cf, set, filter);
                }

                if (collider.TryGetComponent <Substance>(out Substance substance))
                {
                    substance.AddToSet(set, filter);
                }

                foreach (var provider in collider.GetComponents <SubstanceProvider>())
                {
                    provider.Substance?.AddToSet(set, filter);
                }

                GetSubstancesFromTag(collider.gameObject.tag, set, filter);
            }
        }
        public static void RetrieveSubstances(Rect rect, SubstanceSet set, ISubstanceFilter filter, LayerMask layerMask, out bool touch, bool noTouchOnTriggers = false)
        {
            List <Collider2D> colliders = GetTouchRect(rect, GetContactFilter(layerMask));

            if (noTouchOnTriggers)
            {
                touch = false;
                foreach (var col in colliders)
                {
                    if (!col.isTrigger)
                    {
                        touch = true;
                        break;
                    }
                }
            }
            else
            {
                touch = colliders.Count > 0;
            }
            //Debug.Log("Colliders: " + colliders.Count);
            RetrieveSubstances(rect, set, filter, colliders, GetContactFilter(layerMask));
        }
Beispiel #11
0
 public abstract void AddToSet(SubstanceSet set, ISubstanceFilter filter);
        private static void GetSubstancesFromTilemap(Rect rect, Tilemap tilemap, Collider2D collider, ContactFilter2D cf, SubstanceSet set, ISubstanceFilter filter)
        {
            if ((cf.useLayerMask && tilemap.gameObject.layer.IsOtherAllInFlag(cf.layerMask)) ||
                (!cf.useTriggers && collider.isTrigger))
            {
                return;
            }

            RectInt tileRect = new RectInt()
            {
                min = (Vector2Int)tilemap.WorldToCell(rect.min), max = (Vector2Int)tilemap.WorldToCell(rect.max)
            };

            tileRect.height += 1;
            tileRect.width  += 1;


#if DEBUG_THIS
            bool debug = filter is PlayerSubstanceFilter f && f.ColliderType == PlayerSubstanceColliderType.Main;
            if (debug)
            {
                Instance.debugRects.Clear();
                Instance.debugPoints.Clear();

                Rect debugRect = new Rect()
                {
                    min = tilemap.CellToWorld((Vector3Int)tileRect.min),
                    max = tilemap.CellToWorld((Vector3Int)tileRect.max)
                };
                Instance.debugRects.Add(new Tuple <Rect, Color>(debugRect, Color.blue));

                Instance.debugRects.Add(new Tuple <Rect, Color>(rect, Color.green));

                List <ContactPoint2D> contacts = new List <ContactPoint2D>();
                collider.GetContacts(contacts);

                foreach (var c in contacts)
                {
                    Instance.debugPoints.Add(new Tuple <Vector3, Color>(c.point, Color.yellow));
                }
            }
#endif

            //Debug.Log("TileRect: " + tileRect);
            foreach (var tilePos in tileRect.allPositionsWithin)
            {
                TileBase tile = tilemap.GetTile((Vector3Int)tilePos);

                //if (tile != null)
                //    Debug.Log("Try Add Tile: " + tile.name);

                if (tile != null && Instance.tileBasedSubstances.TryGetValue(tile, out List <Substance> subs))
                {
                    if (rect.Overlap(tilemap.GetRectAtPos(tilePos), out Rect overlap))
                    {
                        foreach (var s in subs)
                        {
                            s.AddToSet(set, filter);
                        }

#if DEBUG_THIS
                        if (debug)
                        {
                            Instance.debugRects.Add(new Tuple <Rect, Color>(overlap, Color.magenta));
                        }
#endif
                    }
                }
            }
        }
Beispiel #13
0
 public void ExecuteQuery(SubstanceSet substanceSet)
 {
     queryables.RemoveWhere(e => e.ExeAddToSet(substanceSet));
 }