using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public static class VesselExtension { public static bool IsNullOrEmpty(this List vessel) { return vessel == null || vessel.Count == 0; } public static bool IsNullOrEmpty(this T[] vessel) { return vessel == null || vessel.Length == 0; } public static bool IsNullOrEmpty(this Dictionary dictionary) { return dictionary == null || dictionary.Count == 0; } public static T GetFirst(this List list) { if (list == null) { throw new ArgumentNullException("List is null."); } if (list.Count == 0) { Debug.Log("List count can't be zero."); return default(T); } return list[0]; } public static T GetLast(this List list) { if (list == null) { throw new ArgumentNullException("List is null."); } if (list.Count == 0) { Debug.Log("List count can't be zero."); return default(T); } return list[list.Count - 1]; } public static T GetFirst(this T[] list) { if (list == null) { throw new ArgumentNullException("Array is null."); } if (list.Length == 0) { Debug.Log("Array count can't be zero."); return default(T); } return list[0]; } public static T GetLast(this T[] list) { if (list == null) { throw new ArgumentNullException("Array is null."); } if (list.Length == 0) { Debug.Log("Array count can't be zero."); return default(T); } return list[list.Length - 1]; } public static T GetRandom(this List list) { if (list == null) { throw new ArgumentNullException("List is null."); } if (list.Count == 0) { Debug.Log("List count can't be zero."); return default(T); } var randomIndex = UnityEngine.Random.Range(0, list.Count); return list[randomIndex]; } }