Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProcessingTags : IComponent
- {
- private Dictionary<int, int> tags = new Dictionary<int, int>();
- private Action actionChanged;
- public void BindTo(Action actionChanged)
- {
- this.actionChanged = actionChanged;
- }
- public bool ContainAny(params int[] filter)
- {
- for (var i = 0; i < filter.Length; i++)
- {
- if (tags.ContainsKey(filter[i])) return true;
- }
- return false;
- }
- public bool ContainAll(params int[] filter)
- {
- for (var i = 0; i < filter.Length; i++)
- {
- if (!tags.ContainsKey(filter[i])) return false;
- }
- return true;
- }
- public bool Contain(int val)
- {
- return tags.ContainsKey(val);
- }
- public void Remove(params int[] ids)
- {
- bool tagsChanged = false;
- foreach (var index in ids)
- {
- int val;
- if (tags.TryGetValue(index, out val))
- {
- val = Mathf.Max(0, val - 1);
- if (val == 0)
- {
- tags.Remove(index);
- tagsChanged = true;
- }
- else tags[index] = val;
- }
- }
- if (tagsChanged == false) return;
- actionChanged();
- }
- public void Remove(int id)
- {
- int val;
- if (tags.TryGetValue(id, out val))
- {
- val = Mathf.Max(0, val - 1);
- if (val == 0)
- {
- tags.Remove(id);
- actionChanged();
- }
- else tags[id] = val;
- }
- }
- public void RemovAll(int id)
- {
- if (tags.ContainsKey(id))
- tags.Remove(id);
- actionChanged();
- }
- public void Add(params int[] ids)
- {
- var c = false;
- foreach (var index in ids)
- {
- if (tags.ContainsKey(index))
- {
- tags[index] += 1;
- continue;
- }
- tags.Add(index, 1);
- c = true;
- }
- if (!c) return;
- actionChanged();
- }
- public void Add(int id)
- {
- if (tags.ContainsKey(id))
- {
- tags[id] += 1;
- return;
- }
- tags.Add(id, 1);
- actionChanged();
- }
- public void Dispose()
- {
- tags.Clear();
- actionChanged = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement