Ejemplo n.º 1
0
        public static EntityFilter Create(FilterRules filterRules, TrackHandler trackedCallback, TrackHandler untrackedCallback, bool callForCurrentEntries = true)
        {
            void SetupFilter(EntityFilter filterToSetup)
            {
                filterToSetup.ListenToTrack(trackedCallback, untrackedCallback);
                if (callForCurrentEntries && trackedCallback != null)
                {
                    filterToSetup.ForEach(x => trackedCallback(x));
                }
            }

            for (int i = _cachedFilters.Count - 1; i >= 0; i--)
            {
                EntityFilter filter = _cachedFilters[i];
                if (filter.FilterRules.Equals(filterRules))
                {
                    AddReference(filter);
                    SetupFilter(filter);
                    return(filter);
                }
            }

            EntityFilter self = new EntityFilter(filterRules);

            AddReference(self);
            _cachedFilters.Add(self);
            SetupFilter(self);
            return(self);
        }
Ejemplo n.º 2
0
 private static void AddReference(EntityFilter instance)
 {
     if (HasReferences(instance))
     {
         _cachedFiltersReferenceCounter[instance]++;
     }
     else
     {
         _cachedFiltersReferenceCounter.Add(instance, 1);
     }
 }
Ejemplo n.º 3
0
        private static void RemoveReference(EntityFilter instance)
        {
            bool remove = false;

            if (HasReferences(instance))
            {
                _cachedFiltersReferenceCounter[instance]--;
                if (_cachedFiltersReferenceCounter[instance] == 0)
                {
                    _cachedFiltersReferenceCounter.Remove(instance);
                    remove = true;
                }
            }
            else
            {
                remove = true;
            }

            if (remove)
            {
                _cachedFilters.Remove(instance);
            }
        }
Ejemplo n.º 4
0
 private static bool HasReferences(EntityFilter instance)
 {
     return(_cachedFiltersReferenceCounter.ContainsKey(instance));
 }
Ejemplo n.º 5
0
 public bool Equals(EntityFilter filter)
 {
     return(Equals(filter.FilterRules));
 }
Ejemplo n.º 6
0
 protected void OnDestroy()
 {
     Entities.Clean(TrackedEntity, UntrackedEntity);
     Entities = null;
 }
Ejemplo n.º 7
0
 protected void Awake()
 {
     Entities = EntityFilter.Create(InitializeFilterRules(FilterRulesBuilder.SetupNoTagsBuilder()), TrackedEntity, UntrackedEntity);
 }