using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using System; /// /// Utility Class used for common methodes which don't fit in a class /// public static class Utility { /// /// Gets the smallest item in an array based on the provided function /// /// Array type /// Array to find smallest item in /// What to compare items with /// public static T minBy(T[] values, Func predicate) { //if empty return null if (values.Length == 0) return default; //Define smallest value as first T min = values[0]; //compare all other values for (int i = 1; i < values.Length; i++) if (predicate(values[i]).CompareTo(predicate(min)) < 0) min = values[i]; //return return min; } }