Skip to content

Instantly share code, notes, and snippets.

@GhatSmith
Created September 24, 2018 22:22
Show Gist options
  • Save GhatSmith/ab056dc82f973dd1057f6ed8c65a78f8 to your computer and use it in GitHub Desktop.
Save GhatSmith/ab056dc82f973dd1057f6ed8c65a78f8 to your computer and use it in GitHub Desktop.
GenericFilter
using System.Collections.Generic;
using UnityEngine;
/// <summary> "Generic class. Include logic if you want to define collection of elements with exceptions" </summary>
[System.Serializable]
public class GenericFilter<T>
{
private enum Type { NothingExcept, AllExcept }
[SerializeField] private Type type = Type.AllExcept;
[SerializeField] private List<T> exceptions = new List<T>();
public bool IsAccepted(T value)
{
switch (type)
{
case Type.AllExcept: return !exceptions.Contains(value);
case Type.NothingExcept: return exceptions.Contains(value);
default: throw new System.NotImplementedException();
}
}
public void AddException(T addedException)
{
if (exceptions.Contains(addedException)) return;
exceptions.Add(addedException);
}
public void RemoveException(T removedException)
{
exceptions.Remove(removedException);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment