using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEngine; using UnityEngine.UIElements; namespace UnityEditor.Graphing.Util { static class UIUtilities { public static bool ItemsReferenceEquals(this IList first, IList second) { if (first.Count != second.Count) { return false; } for (int i = 0; i < first.Count; i++) { if (!ReferenceEquals(first[i], second[i])) { return false; } } return true; } public static int GetHashCode(params object[] objects) { return GetHashCode(objects.AsEnumerable()); } public static int GetHashCode(IEnumerable objects) { var hashCode = 17; foreach (var @object in objects) { hashCode = hashCode * 31 + (@object == null ? 79 : @object.GetHashCode()); } return hashCode; } public static IEnumerable ToEnumerable(this T item) { yield return item; } public static void Add(this VisualElement visualElement, T elementToAdd, Action action) where T : VisualElement { visualElement.Add(elementToAdd); action(elementToAdd); } public static IEnumerable GetTypesOrNothing(this Assembly assembly) { try { return assembly.GetTypes(); } catch { return Enumerable.Empty(); } } public static Vector2 CalculateCentroid(IEnumerable nodePositions) { Vector2 centroid = Vector2.zero; int count = 1; foreach (var position in nodePositions) { centroid = centroid + (position - centroid) / count; ++count; } return centroid; } } }