暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EditorUtilities.cs 1.2KB

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using Unity.Mathematics;
  3. using UnityEngine;
  4. namespace UnityEditor.U2D.Animation
  5. {
  6. internal static class EditorUtilities
  7. {
  8. /// <summary>
  9. /// Checks if element exists in array independent of the order of X and Y.
  10. /// </summary>
  11. public static bool ContainsAny(this int2[] array, int2 element)
  12. {
  13. return Array.FindIndex(array, e =>
  14. (e.x == element.x && e.y == element.y) ||
  15. (e.y == element.x && e.x == element.y)) != -1;
  16. }
  17. public static int2[] ToInt2(Vector2Int[] source) => Array.ConvertAll(source, e => new int2(e.x, e.y));
  18. public static Vector2Int[] ToVector2Int(int2[] source) => Array.ConvertAll(source, e => new Vector2Int(e.x, e.y));
  19. public static float2[] ToFloat2(Vector2[] source) => Array.ConvertAll(source, e => (float2)e);
  20. public static Vector2[] ToVector2(float2[] source) => Array.ConvertAll(source, e => (Vector2)e);
  21. public static T[] CreateCopy<T>(T[] source) where T : struct
  22. {
  23. var copy = new T[source.Length];
  24. Array.Copy(source, copy, source.Length);
  25. return copy;
  26. }
  27. }
  28. }