A game about forced loneliness, made by TACStudios
at master 81 lines 2.1 kB view raw
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Reflection; 5using UnityEngine; 6using UnityEngine.UIElements; 7 8namespace UnityEditor.Graphing.Util 9{ 10 static class UIUtilities 11 { 12 public static bool ItemsReferenceEquals<T>(this IList<T> first, IList<T> second) 13 { 14 if (first.Count != second.Count) 15 { 16 return false; 17 } 18 19 for (int i = 0; i < first.Count; i++) 20 { 21 if (!ReferenceEquals(first[i], second[i])) 22 { 23 return false; 24 } 25 } 26 27 return true; 28 } 29 30 public static int GetHashCode(params object[] objects) 31 { 32 return GetHashCode(objects.AsEnumerable()); 33 } 34 35 public static int GetHashCode<T>(IEnumerable<T> objects) 36 { 37 var hashCode = 17; 38 foreach (var @object in objects) 39 { 40 hashCode = hashCode * 31 + (@object == null ? 79 : @object.GetHashCode()); 41 } 42 return hashCode; 43 } 44 45 public static IEnumerable<T> ToEnumerable<T>(this T item) 46 { 47 yield return item; 48 } 49 50 public static void Add<T>(this VisualElement visualElement, T elementToAdd, Action<T> action) 51 where T : VisualElement 52 { 53 visualElement.Add(elementToAdd); 54 action(elementToAdd); 55 } 56 57 public static IEnumerable<Type> GetTypesOrNothing(this Assembly assembly) 58 { 59 try 60 { 61 return assembly.GetTypes(); 62 } 63 catch 64 { 65 return Enumerable.Empty<Type>(); 66 } 67 } 68 69 public static Vector2 CalculateCentroid(IEnumerable<Vector2> nodePositions) 70 { 71 Vector2 centroid = Vector2.zero; 72 int count = 1; 73 foreach (var position in nodePositions) 74 { 75 centroid = centroid + (position - centroid) / count; 76 ++count; 77 } 78 return centroid; 79 } 80 } 81}