Advertisement
nbannister

UnityListExtensions

Dec 10th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public static class UnityListExtensions {
  7.  
  8. private static Random rng = new Random();
  9.  
  10. public static void Shuffle<T>(this IList<T> list) {
  11. int n = list.Count;
  12. while (n > 1) {
  13. n--;
  14. int k = rng.Next(n + 1);
  15. T value = list[k];
  16. list[k] = list[n];
  17. list[n] = value;
  18. }
  19. }
  20.  
  21. public static void RemoveAndDestroy<T> (this List<T> list, T behaviour) where T: MonoBehaviour {
  22. list.Remove (behaviour);
  23. GameObject.Destroy (behaviour.gameObject);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement