public static T findNextEligible <T>(T[] list, System.Predicate <T> matchCurrent, System.Predicate <T> matchEligible, bool iterateBackwards) { int iter = iterateBackwards ? -1 : 1; int startIndex = findIndex(list, matchCurrent); int length = list.Length; int index; for (int i = 1; i <= length; i++)//will always loop around to catch the start index... { index = startIndex + iter * i; while (index >= length) { index -= length; } while (index < 0) { index += length; } if (matchEligible.Invoke(list[index])) { return(list[index]); } } return(default(T)); }
private void OnTriggerEnter(Collider other) { Debug.Log("Trigger was entered by " + other.name); if (_predicate.Invoke(other)) { _callback.Invoke(); } }