12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public static class ExtensionList
- {
- public static T Last<T>(this List<T> list, int index)
- {
- return list[list.Count - 1 - index];
- }
- public static T Prev<T>(this List<T> list, int index)
- {
- return list[(index + list.Count - 1) % list.Count];
- }
- public static T Next<T>(this List<T> list, int index)
- {
- return list[(index + 1) % list.Count];
- }
- public static T Random<T>(this List<T> list, bool remove = false)
- {
- if (list.Count == 0)
- {
- Debug.Log("Count is 0");
- }
- int index = UnityEngine.Random.Range(0, list.Count);
- if (remove)
- {
- T result = list[index];
- list.RemoveAt(index);
- return result;
- }
- else
- {
- return list[index];
- }
- }
- public static bool Valid<T>(this List<T> list)
- {
- if (list == null || list.Count == 0)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public static bool UniqueAdd<T>(this List<T> list, T obj)
- {
- if (list.Contains(obj) == false)
- {
- list.Add(obj);
- return true;
- }
- else
- {
- return false;
- }
- }
- public static void LastRemoveAt<T>(this List<T> list, int index)
- {
- list.RemoveAt(list.Count - 1 - index);
- }
- }
|