ExtensionMethod.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace ShotSimulator.Tool
  5. {
  6. public static class ExtensionMethod
  7. {
  8. public static Vector3Int ToVector3Int(this Vector3 value)
  9. {
  10. return new Vector3Int((int)value.x, (int)value.y, (int)value.z);
  11. }
  12. public static List<Vector3> GetGameObjectWorldPosition<T>(this List<T> objs) where T : MonoBehaviour
  13. {
  14. List<Vector3> positions = new List<Vector3>();
  15. for (int i = 0; i < objs.Count; i++)
  16. {
  17. positions.Add(objs[i].transform.position);
  18. }
  19. return positions;
  20. }
  21. public static void FisherYatesShuffle<T>(this IList<T> list)
  22. {
  23. int listCount = list.Count;
  24. while (listCount > 1)
  25. {
  26. listCount--;
  27. int randomIndex = Random.Range(0, listCount);
  28. T value = list[randomIndex];
  29. list[randomIndex] = list[listCount];
  30. list[listCount] = value;
  31. }
  32. }
  33. }
  34. }