using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Dreamteck.Utilities { public static class Utilities { public static T SerializableClone(this T obj) { return JsonUtility.FromJson(JsonUtility.ToJson(obj)); } public static void Shuffle(this IList list) { int n = list.Count; while (n > 1) { n--; int k = UnityEngine.Random.Range(0, n + 1); list.Swap(k, n); } } public static void RemoveAtUnsorted(this List list, int i) { var last = list.Count - 1; list[i--] = list[last]; list.RemoveAt(last); } public static T PopLast(this IList list) { T last = list[list.Count - 1]; list.RemoveAt(list.Count - 1); return last; } public static void Swap(this IList list, int left, int right) { T value = list[left]; list[left] = list[right]; list[right] = value; } public static void SafeInvoke(this Delegate del, params object[] parameters) { foreach (var handler in del.GetInvocationList()) { try { handler.Method.Invoke(handler.Target, parameters); } catch (Exception exception) { Debug.LogException(exception); } } } public static T PopRandom(this List list) { if (list.Count > 0) { int index = UnityEngine.Random.Range(0, list.Count); T element = list[index]; list.RemoveAt(index); return element; } throw new ArgumentException("Attempting to remove an element from an empty list"); } public static bool HasCommandLineArgument(string name) { var args = Environment.GetCommandLineArgs(); for (int i = 0; i < args.Length; i++) { if (args[i] == name) { return true; } } return false; } } }