using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
|
public static class VesselExtension
|
{
|
|
public static bool IsNullOrEmpty<T>(this List<T> vessel)
|
{
|
return vessel == null || vessel.Count == 0;
|
}
|
|
public static bool IsNullOrEmpty<T>(this T[] vessel)
|
{
|
return vessel == null || vessel.Length == 0;
|
}
|
|
public static bool IsNullOrEmpty<T0, T1>(this Dictionary<T0, T1> dictionary)
|
{
|
return dictionary == null || dictionary.Count == 0;
|
}
|
|
public static T GetFirst<T>(this List<T> 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<T>(this List<T> 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<T>(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<T>(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<T>(this List<T> 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];
|
}
|
|
}
|