Created
September 24, 2018 22:22
-
-
Save GhatSmith/ab056dc82f973dd1057f6ed8c65a78f8 to your computer and use it in GitHub Desktop.
GenericFilter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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