A game about forced loneliness, made by TACStudios
1using System.Collections.Generic; 2 3namespace UnityEngine.InputSystem.Utilities 4{ 5 /// <summary> 6 /// Compare two <see cref="Vector2"/> by magnitude. 7 /// </summary> 8 /// <example> 9 /// <code> 10 /// </code> 11 /// public class CompositeWithVector2Part : InputBindingComposite&lt;Vector2&gt; 12 /// { 13 /// [InputControl(layout = "Vector2")] 14 /// public int part; 15 /// 16 /// public override Vector2 ReadValue(ref InputBindingCompositeContext context) 17 /// { 18 /// // Return the Vector3 with the greatest magnitude. 19 /// return context.ReadValue&lt;Vector2, Vector2MagnitudeComparer&gt;(part); 20 /// } 21 /// } 22 /// </example> 23 public struct Vector2MagnitudeComparer : IComparer<Vector2> 24 { 25 public int Compare(Vector2 x, Vector2 y) 26 { 27 var lenx = x.sqrMagnitude; 28 var leny = y.sqrMagnitude; 29 30 if (lenx < leny) 31 return -1; 32 if (lenx > leny) 33 return 1; 34 return 0; 35 } 36 } 37 38 /// <summary> 39 /// Compare two <see cref="Vector3"/> by magnitude. 40 /// </summary> 41 /// <example> 42 /// <code> 43 /// </code> 44 /// public class CompositeWithVector3Part : InputBindingComposite&lt;Vector3&gt; 45 /// { 46 /// [InputControl(layout = "Vector3")] 47 /// public int part; 48 /// 49 /// public override Vector3 ReadValue(ref InputBindingCompositeContext context) 50 /// { 51 /// // Return the Vector3 with the greatest magnitude. 52 /// return context.ReadValue&lt;Vector3, Vector2MagnitudeComparer&gt;(part); 53 /// } 54 /// } 55 /// </example> 56 public struct Vector3MagnitudeComparer : IComparer<Vector3> 57 { 58 public int Compare(Vector3 x, Vector3 y) 59 { 60 var lenx = x.sqrMagnitude; 61 var leny = y.sqrMagnitude; 62 63 if (lenx < leny) 64 return -1; 65 if (lenx > leny) 66 return 1; 67 return 0; 68 } 69 } 70}