Class Leap::Utils¶
- class Leap.Utils¶
Public Static Functions
- static void Swap<T> (ref T a, ref T b)¶
-
Swaps the references of a and b. Note that you can pass in references to array elements if you want!
- static void Swap<T> (this IList<T> list, int a, int b)
-
Utility extension to swap the elements at index a and index b.
- static void Swap<T> (this T[] array, int a, int b)
-
Utility extension to swap the elements at index a and index b.
- static T[] Reverse<T> (this T[] array)¶
System.Array.Reverse is actually surprisingly complex / slow. This is a basic generic implementation of the reverse algorithm. Returns the passed-in reference to allow call chaining.
- static void Reverse<T> (this T[] array, int start, int length)
System.Array.Reverse is actually surprisingly complex / slow. This is a basic generic implementation of the reverse algorithm.
- static bool ImplementsInterface (this Type type, Type ifaceType)¶
Returns whether this type implements the argument interface type. If the argument type is not an interface, returns false.
- static List<int> GetSortedOrder<T> (this IList<T> list)¶
Given a list of comparable types, return an ordering that orders the elements into sorted order. The ordering is a list of indices where each index refers to the element located at that index in the original list.
- static T[] Require<T> (ref T[] arr)¶
Enforces the requirement that the argument-by-ref array is non-null. If it’s null, a new one of length 0 will be allocated. No length requirement is enforced.
- static T[] Require<T> (ref T[] arr, int length, Func<int, T> createAtIdx)
Enforces the requirement that the argument-by-ref array is non-null, and that it is the required length. The passed lambda is called with each index if the array is re-initialized to match the required length.
- static T[] Require<T> (ref T[] arr, int length)
Enforces the requirement that the argument-by-ref array is non-null and that its length is the argument requiredLength. If either required invariant is not satisfied, a new array is allocated and the reference becomes the newly-allocated array. Any values in the original array are transferred to the new array when this occurs.
The final array that satisfies the non-null and length invariants is returned, whether it’s the original array or the newly-allocated one.
- static T[] Require<T> (ref T[] arr, T item0)
Enforces the requirement that the argument-by-ref array is non-null and that it contains the arguments that follow in sequence. If the array is null or the wrong length, a new array is allocated and the reference becomes the newly-allocated array. Any values in the original array are transferred to the new array when this occurs.
The final array that satisfies the non-null length, and contents invariants is returned, whether it’s the original array or the newly-allocated one.
- static T[] Require<T> (ref T[] arr, T item0, T item1)
Enforces the requirement that the argument-by-ref array is non-null and that it contains the arguments that follow in sequence. If the array is null or the wrong length, a new array is allocated and the reference becomes the newly-allocated array. No re-allocation occurs if only the contents need to change.
The final array that satisfies the non-null, length, and content invariants is returned, whether it’s the original array or the newly-allocated one.
- static T[] Require<T> (ref T[] arr, T item0, T item1, T item2, T item3)
Enforces the requirement that the argument-by-ref array is non-null and that it contains the arguments that follow in sequence. If the array is null or the wrong length, a new array is allocated and the reference becomes the newly-allocated array. No re-allocation occurs if only the contents need to change.
The final array that satisfies the non-null, length, and content invariants is returned, whether it’s the original array or the newly-allocated one.
- static T[] Require<T> (ref T[] arr, T item0, T item1, T item2, T item3, T item4)
Enforces the requirement that the argument-by-ref array is non-null and that it contains the arguments that follow in sequence. If the array is null or the wrong length, a new array is allocated and the reference becomes the newly-allocated array. No re-allocation occurs if only the contents need to change.
The final array that satisfies the non-null, length, and content invariants is returned, whether it’s the original array or the newly-allocated one.
- static List<T> RequireLen<T> (ref List<T> list, int length)¶
Enforces the requirement that the argument-by-ref List is non-null and that it is exactly as long as
length
.
- static List<T> Require<T> (ref List<T> list, T item0)
Enforces the requirement that the argument-by-ref List is non-null and that it (exactly) contains the arguments that follow it.
The final list that satisfies the non-null and length invariants is returned, whether it’s the original array or a newly-allocated one.
- static List<T> Require<T> (ref List<T> list, T item0, T item1)
Enforces the requirement that the argument-by-ref List is non-null and that it (exactly) contains the arguments that follow it.
The final list that satisfies the non-null and length invariants is returned, whether it’s the original array or a newly-allocated one.
- static List<T> Require<T> (ref List<T> list, T item, T[] items)
Enforces the requirement that the argument-by-ref List is non-null and that it (exactly) contains the arguments that follow it.
- static T Require<T> (ref T t, Func<T> makeValidT)
Enforces the requirement that T is not null. If it is, creates a new valid T by calling the passed function. If a new T is created in this way, the object reference is switched out for the new T.
The created (or original, if already non-default) T is returned for convenience.
- static ? T Require< T > (ref T? t, Func< T > makeValidT)
Enforces the requirement that T is not null. If it is, creates a new valid T by calling the passed function. If a new T is created in this way, the object reference is switched out for the new T.
The created (or original, if already non-default) T is returned for convenience.
- static T Require<T> (ref T t)
Enforces the requirement that T is not null. If it is, creates a new valid T by calling new T(). If a new T is created in this way, the object reference is switched out for the new T.
The created (or original, if already non-default) T is returned for convenience.
- static T OrIfNull<T> (this T t, T otherwise)¶
Returns the argument object if this object is null, or this object if it is non-null.
- static string TrimEnd (this string str, int characters)¶
Trims a specific number of characters off of the end of the provided string. When the number of trimmed characters is equal to or greater than the length of the string, the empty string is always returned.
- static string TrimStart (this string str, int characters)¶
Trims a specific number of characters off of the beginning of the provided string. When the number of trimmed characters is equal to or greater than the length of the string, the empty string is always returned.
- static string Capitalize (this string str)¶
Capitalizes a simple string. Only looks at the first character, so if your string has any kind of non-letter character as the first character this method will do nothing.
- static string GenerateNiceName (string value)¶
Takes a variable-like name and turns it into a nice human readable name. Examples:
_privateVar => Private Var multBy32 => Mult By 32 the_key_code => The Key Code CamelCaseToo => Camel Case Too _is2_equalTo_5 => Is 2 Equal To 5 GetTheSCUBANow => Get The SCUBA Now m_privateVar => Private Var kConstantVar => Constant Var
- static Vector3 ToVector3 (this string str)¶
Converts a string of three floats (e.g. “(1.0, 2.0, 3.0)”) to a Vector3 Credit: https://discussions.unity.com/t/string-to-vector3/158166/2 Returns Vector3.zero if incorrect string passed in
- static string ToArrayString<T> (this IEnumerable<T> enumerable, Func<T, string> toStringFunc = null, int limit = null)¶
Prints the elements of an array in a bracket-enclosed, comma-delimited list, prefixed by the elements’ type.
- static string ToCodeArrayString (this IEnumerable<Vector3> vectors, string language = null)¶
Supported languages: “csharp”, “python”
- static Vector2 Perpendicular (this Vector2 vector)¶
Returns a vector that is perpendicular to this vector. The returned vector will have the same length as the input vector.
- static Vector3 Perpendicular (this Vector3 vector)
Returns a vector that is perpendicular to this vector. The returned vector is not guaranteed to be a unit vector, nor is its length guaranteed to be the same as the source vector’s.
- static Vector3 TimedExtrapolate (Vector3 a, float aTime, Vector3 b, float bTime, float extrapolatedTime)¶
Extrapolates using time values for positions a and b at extrapolatedTime.
- static Quaternion TimedExtrapolate (Quaternion a, float aTime, Quaternion b, float bTime, float extrapolatedTime)
Extrapolates using time values for rotations a and b at extrapolatedTime.
- static bool NextTuple (IList<int> tuple, int maxValue)¶
A specification of the generic NextTuple method that only works for integers ranging from 0 inclusive to maxValue exclusive.
- static bool NextTuple<T> (IList<T> tuple, Func<T, T> nextItem)
Given one tuple of a collection of possible tuples, mutate it into the next tuple in the in the lexicographic sequence, or into the first tuple if the last tuple has been reached.
The items of the tuple must be comparable to each other. The getNext function takes an item and returns the next item in the lexicographic sequence, or the first item if there is no next item.
- Return
Returns true if the new tuple comes after the input tuple, false otherwise.
- static void ForEach<T> (this T[] arr, Action<T> doFunc)¶
Executes the delegate for each object in the array that is non-null.
- static void ForEach<T> (this object[] arr, Action<T> doFunc)
Executes the delegate for each object in the array that can be cast to the generic argument type. The delegate is not called if the cast results in null.
- static void Transform<T, Aux> (this T[] arr, Aux aux, Func<T, Aux, T> mapFunc)¶
Modifies each element of the array in-place using
mapFunc
.
- static void Transform<T> (this T[] arr, Func<T, T> mapFunc)
Modifies each element of the array in-place using
mapFunc
.
- static bool ContainsValue<T> (this T[] arr, T value)¶
Search support for arrays of types that implement IEquatable, e.g. many standard value types like
int
andfloat
.
- static bool Contains<T> (this T[] arr, T value)¶
Returns whether the array contains the value via Array.IndexOf.
- static T[] CopyFrom<T> (this T[] dst, T[] src, int sO, int dO, int num)¶
Copy with range arguments. sO = sourceOffset, dO = dstOffset, num = number of elements to copy.
- static T[] CopyFrom<T> (this T[] dst, T[] src)
Calls CopyTo from the argument src to dst. Expects the arrays to have the same length.
- static T[] Fill<T> (this T[] array, T fillWith)¶
Sets all elements in the array of type T to the argument value.
- static void Add<T> (this List<T> list, T t0, T t1, T t2)
Adds t0, t1, then t2 to this list.
- static void Add<T> (this List<T> list, T t0, T t1, T t2, T t3)
Adds t0, t1, t2, then t3 to this list.
- static void ForEach<T> (this List<T> list, Func<T, T> applyFunc)
Applies the function to each item in the list, in-place. Also known as a “map” operation.
- static void ForEach<T, Aux> (this List<T> list, Aux aux, Func<T, Aux, T> applyFunc)
Applies the function to each item in the list, in-place. Also known as a “map” operation. Supports an auxiliary argument to avoid allocation in lambdas.
- static List<T> Cleared<T> (this List<T> list)¶
Calls
Clear()
on the list and returns it. Useful for chain calls on lists, because the built-in listClear()
returns null.
- static List<T> CopyFrom<T> (this List<T> dst, List<T> src, Action<T, T> copyElementFunc, bool dontClear = false)
Copies each element from src by calling the copyElementFunc. If the source list is null or empty, the destination list will be emptied (unless
dontClear
is passed).Returns the destination List for convenience.
- static T UnwrapOr<T> (this T nullable, T defaultValue)¶
Returns the value of the nullable if it has one, or returns defaultValue.
- static bool IsObjectPartOfPrefabAsset (UnityEngine.Object obj)¶
Gets whether the target object is part of a prefab asset (excluding prefab instances.) Compiles differently pre- and post-2018.3. Also compiles differently in builds, where this method always returns false.
- static bool TryGetComponents<T> (this Component source, out T[] components)¶
Try to get all components of type from the provided Component’s GameObject
- static bool TryGetComponentInParent<T> (this Component source, out T component)¶
Try to get the given component of type from the provided Component’s Parent
- static bool TryGetComponentsInParent<T> (this Component source, out T[] components)¶
Try to get the given components of type from the provided Component’s Parent
- static bool TryGetComponentInChildren<T> (this Component source, out T component, bool includeSelf = true, bool includeInactive = false)¶
Try to get the given component of type from the provided Component’s self or children
- static bool TryGetComponentsInChildren<T> (this Component source, out T[] components, bool includeSelf = true, bool includeInactive = false)¶
Try to get the given component of type from the provided Component’s self or children
- static ChildrenEnumerator GetChildren (this Transform t)¶
Returns the children of this Transform in sibling index order.
- static void GetAllChildren (this Transform t, List<Transform> toFill, bool breadthFirst = false)¶
Scans all the children in order of the argument Transform, appending each transform it finds to toFill. Children are added depth-first by default.
Pass breadthFirst: true to fill the list breadth-first instead.
- static Transform FindChild (this Transform t, string[] possibleNames, bool caseSensitive = true)¶
As FindChild(string), but tries to find the first string first, then moves onto each next string until a non-null matching child is found.
- static Transform FindChild (this Transform t, string withName, bool caseSensitive = true)
Returns the first child whose name includes the ‘withName’ argument string. Optionally pass caseSensitive: false to ignore case. Children are scanned deeply using Leap.Utils.GetAllChildren. If no such child exists, returns null.
- static void ResetLocalTransform (this Transform t)¶
Sets the localPosition, localRotation, and localScale to their default values: Vector3.zero, Quaternion.identity, and Vector3.one.
- static void ResetLocalPose (this Transform t)¶
Sets the localPosition and localRotation of this Transform to Vector3.zero and Quaternion.identity. Doesn’t affect localScale.
- static Vector3 GetClosestAxisDirection (this Transform t, Vector3 toDir)¶
Determines the cardinal direction in the rotated frame that most closely points towards the global-frame argument direction. The positive or negative X, Y, or Z axis directions (converted to global space via the rotated frame) are the six possible return values.
- static void SetMatrix (this Transform t, Matrix4x4 targetMatrix, bool allowAtEditTime = false)¶
Attempts to set the
localToWorldMatrix
of this Transform to the target matrix by retreiving a pose and lossy scale from the target matrix and adjusting the transform data appropriately. This operation won’t work for projective matrices, and is disabled at edit-time by default because it can destroy Transform information (enable edit-time by passingallowAtEditTime
at your own risk).
- static Matrix4x4 LocalFromWorld (this Transform t)¶
Returns the worldToLocal matrix of the transform.
- static Matrix4x4 WorldFromLocal (this Transform t)¶
Returns the localToWorld matrix of the transform.
- static void SetLossyScale (this Transform t, Vector3 lossyScale)¶
Tries to set the lossyScale of the Transform to the argument. Will likely fail in various edge cases, use at your own risk.
- static float Distance (Transform t0, Transform t1)¶
Returns the world-space distance between the origins of two Transforms.
- static void LookAwayFrom (this Transform thisTransform, Transform transform)¶
Similar to Unity’s Transform.LookAt(), but resolves the forward vector of this Transform to point away from the argument Transform.
Useful for billboarding Quads and UI elements whose forward vectors should match rather than oppose the Main Camera’s forward vector.
Optionally, you may also pass an upwards vector, which will be provided to the underlying Quaternion.LookRotation. Vector3.up will be used by default.
- static void LookAwayFrom (this Transform thisTransform, Transform transform, Vector3 upwards)
Similar to Unity’s Transform.LookAt(), but resolves the forward vector of this Transform to point away from the argument Transform.
Allows specifying an upwards parameter; this is passed as the upwards vector to the Quaternion.LookRotation.
- Param thisTransform
- Param transform
- static Vector3 GetClosestAxisDirection (this Quaternion q, Vector3 toDir)
Determines the cardinal direction in the rotated frame that most closely points towards the global-frame argument direction. The positive or negative X, Y, or Z axis directions (converted to global space via the rotated frame) are the six possible return values.
- static Vector3 GetClosestLocalAxisDirection (Vector3 toLocalDir)¶
Determines the cardinal direction in the rotated frame that most closely points towards the local-frame argument direction. The positive or negative X, Y, or Z axis directions are the six possible return values.
- static Vector3 ToVector3 (this Vector4 v4)
Returns a Vector3 containing the X, Y, and Z components of this Vector4. Note that an implicit conversion exists from Vector4 to Vector3 already, so this extension method is only useful if you specifically want an explicit conversion.
- static Vector3 InLocalSpace (this Vector3 v, Transform t)¶
Returns this vector converted from world space to the local space of the argument Transform.
- static Vector4 WithW (this Vector3 v, float w)¶
Returns a Vector4 with this Vector3’s values and the specified w value.
- static Vector3 Pivot (this Vector3 point, Vector3 pivot, Quaternion rotation)¶
Returns the point pivoted around the argument pivot point with the argument rotation.
- static Quaternion GetAxisFromToRotation (this Vector3 v, Vector3 toDir, Vector3 axis, out float angle, float minAngle = null, float maxAngle = null)¶
Constructs an AngleAxis rotation that aligns this vector to the argument
toDir
on a single axis, by projecting it onto the plane defined by the axis and rotating v (also on that plane) to align with it.Can optionally receive the computed signed angle out to the
angle
parameter.
- static Quaternion GetAxisFromToRotation (this Vector3 v, Vector3 toDir, Vector3 axis, float minAngle = null, float maxAngle = null)
Constructs an AngleAxis rotation that aligns this vector to the argument
toDir
on a single axis, by projecting it onto the plane defined by the axis and rotating v (also on that plane) to align with it.
- static Vector3 ToAngleAxisVector (this Quaternion q)¶
Converts the quaternion into an axis and an angle and returns the vector axis * angle. Angle magnitude is measured in degrees, not radians; this requires conversion to radians if being used to set the angular velocity of a PhysX Rigidbody.
- static Quaternion QuaternionFromAngleAxisVector (Vector3 angleAxisVector)¶
Returns a Quaternion described by the provided angle axis vector. Expects the magnitude (angle) to be in degrees, not radians.
- static Quaternion ToNormalized (this Quaternion quaternion)¶
Returns a normalized Quaternion from the input quaternion. If the input quaternion is zero-length (AKA the default Quaternion), the identity Quaternion is returned.
- static Quaternion FaceTargetWithoutTwist (Vector3 fromPosition, Vector3 targetPosition, bool flip180 = false)¶
Returns the rotation that makes a transform at fromPosition point its forward vector at targetPosition and keep its rightward vector parallel with the horizon defined by a normal of Vector3.up.
For example, this will point an interface panel at a user camera while maintaining the alignment of text and other elements with the horizon line.
- Return
- static Quaternion FaceTargetWithoutTwist (Vector3 fromPosition, Vector3 targetPosition, Vector3 upwardDirection, bool flip180 = false)
Returns the rotation that makes a transform at fromPosition point its forward vector at targetPosition and keep its rightward vector parallel with the horizon defined by the upwardDirection normal.
For example, this will point an interface panel at a user camera while maintaining the alignment of text and other elements with the horizon line.
- static Quaternion Flipped (this Quaternion q)¶
Returns the quaternion with every component negated.
- static Quaternion MirroredX (this Quaternion q)¶
Returns the quaternion with X and W negated.
- static Quaternion MirroredY (this Quaternion q)¶
Returns the quaternion with Y and W negated.
- static Quaternion MirroredZ (this Quaternion q)¶
Returns the quaternion with Z and W negated.
- static void CompressQuatToBytes (Quaternion quat, byte[] buffer, ref int offset)¶
Fills the provided bytes buffer starting at the offset with a compressed form of the argument quaternion. The offset is also shifted by 4 bytes.
Use Leap.Utils.DecompressBytesToQuat to decode this representation. This encoding ONLY works with normalized Quaternions, taking advantage of the fact that their components sum to 1 to only encode three of Quaternion components. As a result, this method encodes a Quaternion as a single unsigned integer (4 bytes).
Sources: https://bitbucket.org/Unity-Technologies/networking/pull-requests/9/quaternion-compression-for-sending/diff and http://stackoverflow.com/questions/3393717/c-sharp-converting-uint-to-byte
- static Quaternion DecompressBytesToQuat (byte[] bytes, ref int offset)¶
Reads 4 bytes from the argument bytes array (starting at the provided offset) and returns a Quaternion as encoded by the Leap.Utils.CompressedQuatToBytes function. Also increments the provided offset by 4.
See the Leap.Utils.CompressedQuatToBytes documentation for more details on the byte representation this method expects.
Sources: https://bitbucket.org/Unity-Technologies/networking/pull-requests/9/quaternion-compression-for-sending/diff and http://stackoverflow.com/questions/3393717/c-sharp-converting-uint-to-byte
- static Quaternion GetQuaternion_Manual (this Matrix4x4 m)¶
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
- static Quaternion GetQuaternion (this Matrix4x4 m)¶
Returns the quaternion defined by the matrices multiply forward and up vectors and passing those vectors into LookRotation. If either the forward or up vectors determined from the input matrix are Vector3.zero, returns Quaternion.identity to avoid console spam.
- static Vector3 GetClosestAxisDirection (this Matrix4x4 m, Vector3 toDir)
Determines the cardinal direction in the matrix’s frame that most closely points towards the global-frame argument direction. The positive or negative X, Y, or Z axis directions (converted to global space via the matrix) are the six possible return values.
- static Vector3 GetPosition (this Matrix4x4 m)¶
Non-projective only (MultiplyPoint3x4(Vector3.zero)).
- static Matrix4x4 Pivot (this Matrix4x4 m, Quaternion q)
Given a Matrix4x4 with some possibly non-identity translation, this operation rotates the matrix by the quaternion
q
usingMatrix4x4.Rotate
, then compensates for any translation the rotation might have introduced. (The effective multiply order is Rotate(q) * m.) Essentially, this operation “pivots” matrices about their translated origin by the argument quaternion.
- static Matrix4x4 Pivot (this Matrix4x4 m, Quaternion q, Vector3 p)
As
Pivot()
with no Vector3 argument, but instead of pivoting the Matrix4x4 about its own local Vector3.zero position, the matrix is pivoting about the argument global positionp
.
- static Matrix4x4 PivotTo (this Matrix4x4 m, Quaternion q)¶
As
Pivot
but the matrix’s rotation matchesq
instead of being rotated byq
at the end.
- static void SetCapsulePoints (this CapsuleCollider capsule, Vector3 a, Vector3 b)¶
Manipulates capsule.transform.position, capsule.transform.rotation, and capsule.height so that the line segment defined by the capsule connects world-space points a and b.
- static void FindColliders<T> (GameObject obj, List<T> colliders, bool includeInactiveObjects = false)¶
Recursively searches the hierarchy of the argument GameObject to find all of the Colliders that are attached to the object’s Rigidbody (or that would be attached to its Rigidbody if it doesn’t have one) and adds them to the provided colliders list. Warning: The provided “colliders” List will be cleared before use.
Colliders that are the children of other Rigidbody elements beneath the argument object are ignored. Optionally, colliders of inactive GameObjects can be included in the returned list; by default, these colliders are skipped.
- static Color ParseHtmlColorString (string htmlString)¶
Just like ColorUtility.TryParseHtmlString but throws a useful error message if it fails.
- static Color LerpHSV (this Color color, Color towardsColor, float t)¶
Lerps this color towards the argument color in HSV space and returns the lerped color.
- static float LerpHue (float h0, float h1, float t)¶
Cyclically lerps hue arguments by t.
- static Vector3 HSVToRGB (Vector3 hsv)¶
As Color.HSVToRGB but using Vector3 as the storage struct. Color components are floats from 0-1.
- static bool IsCompressible (TextureFormat format)¶
Returns whether or not the given format is a valid input to EditorUtility.CompressTexture();
- static float Area (this Rect rect)¶
Returns the area of the Rect, width * height.
- static Rect Extrude (this Rect r, float margin)¶
Returns a new Rect with the argument as an outward margin on each border of this Rect; the result is a larger Rect.
- static Rect PadInner (this Rect r, float padding)¶
Returns a new Rect with the argument padding as a margin relative to each border of the provided Rect.
- static Rect PadInner (this Rect r, float padTop, float padBottom, float padLeft, float padRight)
Returns a new Rect with the argument padding as a margin inward from each corresponding border of the provided Rect. The returned Rect will never collapse to have a width or height less than zero, and its resulting size will never be larger than the input rect.
- static Rect PadTop (this Rect r, float padding, out Rect marginRect)¶
Returns the Rect if padded on the top by the padding amount, and optionally outputs the remaining margin into marginRect.
- static Rect PadBottom (this Rect r, float padding, out Rect marginRect)¶
Returns the Rect if padded on the bottom by the padding amount, and optionally outputs the remaining margin into marginRect.
- static Rect PadLeft (this Rect r, float padding, out Rect marginRect)¶
Returns the Rect if padded on the left by the padding amount, and optionally outputs the remaining margin into marginRect.
- static Rect PadRight (this Rect r, float padding, out Rect marginRect)¶
Returns the Rect if padded on the right by the padding amount, and optionally outputs the remaining margin into marginRect.
- static Rect TakeTop (this Rect r, float heightFromTop)¶
Return a margin of the given height on the top of the input Rect. You can’t Take more than there is Rect to take from.
- static Rect TakeBottom (this Rect r, float heightFromBottom)¶
Return a margin of the given height on the bottom of the input Rect. You can’t Take more than there is Rect to take from.
- static Rect TakeLeft (this Rect r, float widthFromLeft)¶
Return a margin of the given width on the left side of the input Rect. You can’t Take more than there is Rect to take from.
- static Rect TakeRight (this Rect r, float widthFromRight)¶
Return a margin of the given width on the right side of the input Rect. You can’t Take more than there is Rect to take from.
- static Rect TakeTop (this Rect r, float padding, out Rect theRest)
Return a margin of the given width on the top of the input Rect, and optionally outputs the rest of the Rect into theRest.
- static Rect TakeBottom (this Rect r, float padding, out Rect theRest)
Return a margin of the given width on the bottom of the input Rect, and optionally outputs the rest of the Rect into theRest.
- static Rect TakeLeft (this Rect r, float padding, out Rect theRest)
Return a margin of the given width on the left side of the input Rect, and optionally outputs the rest of the Rect into theRest.
- static Rect TakeRight (this Rect r, float padding, out Rect theRest)
Return a margin of the given width on the right side of the input Rect, and optionally outputs the rest of the Rect into theRest.
- static Rect TakeHorizontal (this Rect r, float lineHeight, out Rect theRest, bool fromTop = true)¶
Returns a horizontal strip of lineHeight of this rect (from the top by default) and provides what’s left of this rect after the line is removed as theRest.
- static HorizontalLineRectEnumerator TakeAllLines (this Rect r, int numLines)¶
Slices numLines horizontal line Rects from this Rect and returns an enumerator that will return each line Rect.
The height of each line is the height of the Rect divided by the number of lines requested.
- static Pose From (this Vector3 position, Pose fromPose)¶
Returns a pose such that fromPose.Then(thisPose) will have this position and the fromPose’s rotation.
- static Pose MirroredX (this Pose pose)
Returns a Pose that has its position and rotation mirrored on the X axis.
- static Pose Negated (this Pose pose)¶
Returns a Pose that has its position and rotation flipped.
- static Pose Pivot (this Pose p, Quaternion q)
Given a Pose with some possibly non-identity translation, this operation rotates the pose by the quaternion
q
, then compensates for any translation the rotation might have introduced. Essentially, this operation “pivots” poses about their translated origin by the argument quaternion.
- static Pose Pivot (this Pose p, Quaternion q, Vector3 pivotPoint)
As
Pivot()
with no Vector3 argument, but instead of pivoting the pose about its own local Vector3.zero position, the pose is pivoted about the argument world positionpivotPoint
.
- static Pose PivotTo (this Pose p, Quaternion q)
As
Pivot
but the pose’s rotation matchesq
instead of being rotated byq
at the end.
- static Matrix4x4 ToUnityRotationMatrix (this LeapInternal.LEAP_MATRIX_3x3 m)¶
Converts a LEAP_MATRIX_3x3 rotation matrix to a Unity Matrix4x4
- Param m
A Leap rotation matrix
- Return
A Unity Rotation Matrix
- static void AddTrackedPoseDriverToCamera (this Camera mainCamera)¶
Adds a tracked pose driver to the given camera if suitable packages are installed. Does nothing if a tracked pose driver already exists on the camera
- static float Map (this float value, float valueMin, float valueMax, float resultMin, float resultMax)¶
Maps the value between valueMin and valueMax to its linearly proportional equivalent between resultMin and resultMax. The input value is clamped between valueMin and valueMax; if this is not desired, see MapUnclamped.
- static float MapUnclamped (this float value, float valueMin, float valueMax, float resultMin, float resultMax)¶
Maps the value between valueMin and valueMax to its linearly proportional equivalent between resultMin and resultMax, without clamping the result value between resultMin and resultMax.
- static float Map01 (float value, float min, float max)¶
Map a float from a range to the 0-1 range. E.g. (34 , 0, 100) returns as 0.34f
- Param value
The value which should be mapped between 0 and 1
- Param min
Min value for the input range
- Param max
Max value for the input range
- Return
- static Vector2 Map (this Vector2 value, float valueMin, float valueMax, float resultMin, float resultMax)
Maps each Vector2 component between valueMin and valueMax to its linearly proportional equivalent between resultMin and resultMax. The input values are clamped between valueMin and valueMax; if this is not desired, see MapUnclamped.
- static Vector2 MapUnclamped (this Vector2 value, float valueMin, float valueMax, float resultMin, float resultMax)
Maps each Vector2 component between valueMin and valueMax to its linearly proportional equivalent between resultMin and resultMax, without clamping the result value between resultMin and resultMax.
- static Vector3 Map (this Vector3 value, float valueMin, float valueMax, float resultMin, float resultMax)
Maps each Vector3 component between valueMin and valueMax to its linearly proportional equivalent between resultMin and resultMax. The input values are clamped between valueMin and valueMax; if this is not desired, see MapUnclamped.
- static Vector3 MapUnclamped (this Vector3 value, float valueMin, float valueMax, float resultMin, float resultMax)
Maps each Vector3 component between valueMin and valueMax to its linearly proportional equivalent between resultMin and resultMax, without clamping the result value between resultMin and resultMax.
- static Vector4 Map (this Vector4 value, float valueMin, float valueMax, float resultMin, float resultMax)
Maps each Vector4 component between valueMin and valueMax to its linearly proportional equivalent between resultMin and resultMax. The input values are clamped between valueMin and valueMax; if this is not desired, see MapUnclamped.
- static Vector4 MapUnclamped (this Vector4 value, float valueMin, float valueMax, float resultMin, float resultMax)
Maps each Vector4 component between valueMin and valueMax to its linearly proportional equivalent between resultMin and resultMax, without clamping the result value between resultMin and resultMax.
- static Vector2 Map (float input, float valueMin, float valueMax, Vector2 resultMin, Vector2 resultMax)
Returns a vector between resultMin and resultMax based on the input value’s position between valueMin and valueMax. The input value is clamped between valueMin and valueMax.
- static Vector3 Map (float input, float valueMin, float valueMax, Vector3 resultMin, Vector3 resultMax)
Returns a vector between resultMin and resultMax based on the input value’s position between valueMin and valueMax. The input value is clamped between valueMin and valueMax.
- static Vector4 Map (float input, float valueMin, float valueMax, Vector4 resultMin, Vector4 resultMax)
Returns a vector between resultMin and resultMax based on the input value’s position between valueMin and valueMax. The input value is clamped between valueMin and valueMax.
- static Vector2 CompMul (this Vector2 A, Vector2 B)¶
Returns a new Vector2 via component-wise multiplication. This operation is equivalent to Vector3.Scale(A, B).
- static Vector3 CompMul (this Vector3 A, Vector3 B)
Returns a new Vector3 via component-wise multiplication. This operation is equivalent to Vector3.Scale(A, B).
- static Vector4 CompMul (this Vector4 A, Vector4 B)
Returns a new Vector4 via component-wise multiplication. This operation is equivalent to Vector3.Scale(A, B).
- static Vector2 CompDiv (this Vector2 A, Vector2 B)¶
Returns a new Vector2 via component-wise division. This operation is the inverse of A.CompMul(B).
- static Vector3 CompDiv (this Vector3 A, Vector3 B)
Returns a new Vector3 via component-wise division. This operation is the inverse of A.CompMul(B).
- static Vector4 CompDiv (this Vector4 A, Vector4 B)
Returns a new Vector4 via component-wise division. This operation is the inverse of A.CompMul(B).
- static Vector2 CompAdd (this Vector2 A, Vector2 B)¶
Returns a new Vector2 via component-wise addition. This operation is the inverse of A.CompSub(B).
- static Vector3 CompAdd (this Vector3 A, Vector3 B)
Returns a new Vector3 via component-wise addition. This operation is the inverse of A.CompSub(B).
- static Vector4 CompAdd (this Vector4 A, Vector4 B)
Returns a new Vector4 via component-wise addition. This operation is the inverse of A.CompSub(B).
- static Vector2 CompSub (this Vector2 A, Vector2 B)¶
Returns a new Vector2 via component-wise subtraction. This operation is the inverse of A.CompAdd(B).
- static Vector3 CompSub (this Vector3 A, Vector3 B)
Returns a new Vector3 via component-wise subtraction. This operation is the inverse of A.CompAdd(B).
- static Vector4 CompSub (this Vector4 A, Vector4 B)
Returns a new Vector4 via component-wise subtraction. This operation is the inverse of A.CompAdd(B).
- static float CompSum (this Vector3 v)
Returns the sum of the components of the input vector.
- static float CompSum (this Vector4 v)
Returns the sum of the components of the input vector.
- static float CompMax (this Vector3 v)
Returns the largest component of the input vector.
- static float CompMax (this Vector4 v)
Returns the largest component of the input vector.
- static float CompMin (this Vector3 v)
Returns the smallest component of the input vector.
- static float CompMin (this Vector4 v)
Returns the smallest component of the input vector.
- static Vector2 CompLerp (this Vector2 A, Vector2 B, Vector2 Ts)¶
Returns a new Vector2 via component-wise Lerp.
- static Vector3 CompLerp (this Vector3 A, Vector3 B, Vector3 Ts)
Returns a new Vector3 via component-wise Lerp.
- static Vector4 CompLerp (this Vector4 A, Vector4 B, Vector4 Ts)
Returns a new Vector4 via component-wise Lerp.
- static Vector2 CompWise (this Vector2 A, Func<float, float> op)¶
Returns a new Vector2 via an component-wise float operation.
- static Vector3 CompWise (this Vector3 A, Func<float, float> op)
Returns a new Vector3 via an component-wise float operation.
- static Vector4 CompWise (this Vector4 A, Func<float, float> op)
Returns a new Vector4 via an component-wise float operation.
- static float From (this float thisFloat, float otherFloat)
Additive From syntax for floats. Evaluated as this float plus the additive inverse of the other float, usually expressed as thisFloat - otherFloat.
For less trivial uses of From/Then syntax, refer to their implementations for Quaternions and Matrix4x4s.
- static float To (this float thisFloat, float otherFloat)¶
Additive To syntax for floats. Evaluated as this float plus the additive inverse of the other float, usually expressed as otherFloat - thisFloat.
For less trivial uses of From/Then syntax, refer to their implementations for Quaternions and Matrix4x4s.
- static float Then (this float thisFloat, float otherFloat)¶
Additive Then syntax for floats. Literally, thisFloat + otherFloat.
- static Vector3 From (this Vector3 thisVector, Vector3 otherVector)
Additive From syntax for Vector3. Literally thisVector - otherVector.
- static Vector3 To (this Vector3 thisVector, Vector3 otherVector)
Additive To syntax for Vector3. Literally otherVector - thisVector.
- static Vector3 Then (this Vector3 thisVector, Vector3 otherVector)
Additive Then syntax for Vector3. Literally thisVector + otherVector. For example: A.Then(B.From(A)) == B.
- static Quaternion From (this Quaternion thisQuaternion, Quaternion otherQuaternion)
A.From(B) produces the quaternion that rotates from B to A. Combines with Then() to produce readable, predictable results: B.Then(A.From(B)) == A.
- static Quaternion To (this Quaternion thisQuaternion, Quaternion otherQuaternion)
A.To(B) produces the quaternion that rotates from A to B. Combines with Then() to produce readable, predictable results: B.Then(B.To(A)) == A.
- static Quaternion Then (this Quaternion thisQuaternion, Quaternion otherQuaternion)
Rotates this quaternion by the other quaternion. This is a rightward syntax for Quaternion multiplication, which normally obeys left-multiply ordering.
- static Pose From (this Pose thisPose, Pose otherPose)
From syntax for Pose structs; A.From(B) returns the Pose that transforms to Pose A from Pose B. Also see To() and Then().
For example, A.Then(B.From(A)) == B.
- static Pose To (this Pose thisPose, Pose otherPose)
To syntax for Pose structs; A.To(B) returns the Pose that transforms from Pose A to Pose B. Also see From() and Then().
For example, A.Then(A.To(B)) == B.
- static Pose Then (this Pose thisPose, Pose otherPose)
Returns the other pose transformed by this pose. This pose could be understood as the parent pose, and the other pose transformed from local this-pose space to world space.
This is similar to matrix multiplication: A * B == A.Then(B). However, order of operations is more explicit with this syntax.
- static Matrix4x4 From (this Matrix4x4 thisMatrix, Matrix4x4 otherMatrix)
A.From(B) produces the matrix that transforms from B to A. Combines with Then() to produce readable, predictable results: B.Then(A.From(B)) == A.
Warning: Scale factors of zero will invalidate this behavior.
- static Matrix4x4 To (this Matrix4x4 thisMatrix, Matrix4x4 otherMatrix)
A.To(B) produces the matrix that transforms from A to B. Combines with Then() to produce readable, predictable results: B.Then(B.To(A)) == A.
Warning: Scale factors of zero will invalidate this behavior.
- static Matrix4x4 Then (this Matrix4x4 thisMatrix, Matrix4x4 otherMatrix)
Transforms this matrix by the other matrix. This is a rightward syntax for matrix multiplication, which normally obeys left-multiply ordering.
- struct ChildrenEnumerator : public IEnumerator<Transform>¶
- struct HorizontalLineRectEnumerator¶