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); }
private static void AddReference(EntityFilter instance) { if (HasReferences(instance)) { _cachedFiltersReferenceCounter[instance]++; } else { _cachedFiltersReferenceCounter.Add(instance, 1); } }
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); } }
private static bool HasReferences(EntityFilter instance) { return(_cachedFiltersReferenceCounter.ContainsKey(instance)); }
public bool Equals(EntityFilter filter) { return(Equals(filter.FilterRules)); }
protected void OnDestroy() { Entities.Clean(TrackedEntity, UntrackedEntity); Entities = null; }
protected void Awake() { Entities = EntityFilter.Create(InitializeFilterRules(FilterRulesBuilder.SetupNoTagsBuilder()), TrackedEntity, UntrackedEntity); }