Show / Hide Table of Contents

Class VectorUtilities

Contains utility functions related to vectors

Inheritance
object
VectorUtilities
Namespace: WeaverCore.Utilities
Assembly: WeaverCore.dll
Syntax
public static class VectorUtilities

Methods

| Edit this page View Source

CalculateSpacedValues(int, float)

Creates an array of values that are evenly spaced together.

Declaration
public static float[] CalculateSpacedValues(int amountOfValues, float spacingBetweenValues)
Parameters
Type Name Description
int amountOfValues

The amount of values to create

float spacingBetweenValues

The amount of spacing between values

Returns
Type Description
float[]

Returns a list of values that are evenly spaced between one another

Examples

For example, if amountOfValues = 7, and spacingBetweenValues = 6, then the following list will be created: [0, -6, 6, -12, 12, -18, 18]

If amountOfValues = 8, and spacingBetweenValues = 4, then the following list will be created: [-2, 2, -6, 6, -10, 10, -14, 14]

| Edit this page View Source

ClampInRange(Vector2, float)

Declaration
public static float ClampInRange(this Vector2 range, float value)
Parameters
Type Name Description
Vector2 range
float value
Returns
Type Description
float
| Edit this page View Source

Decelerate(Vector2, Vector2)

Multiplies the components of the source vector with the components of the deceleration vector. If any of the deceneration components are float.NaN, that component will be ignored. If the x component of deceleration is float.NaN, the x component of source will not be changed

Declaration
public static Vector2 Decelerate(Vector2 source, Vector2 deceleration)
Parameters
Type Name Description
Vector2 source

The source vector to decelerate

Vector2 deceleration

The amount of deceleration to be applied to the source vector

Returns
Type Description
Vector2

The decelerated source vector

| Edit this page View Source

Decelerate(Vector3, Vector3)

Multiplies the components of the source vector with the components of the deceleration vector. If any of the deceneration components are float.NaN, that component will be ignored. If the x component of deceleration is float.NaN, the x component of source will not be changed

Declaration
public static Vector3 Decelerate(Vector3 source, Vector3 deceleration)
Parameters
Type Name Description
Vector3 source

The source vector to decelerate

Vector3 deceleration

The amount of deceleration to be applied to the source vector

Returns
Type Description
Vector3

The decelerated source vector

| Edit this page View Source

DegreesToVector(float, float)

Converts an angle (in degrees) into a vector pointing in the same direction

Declaration
public static Vector2 DegreesToVector(this float angle, float magnitude = 1)
Parameters
Type Name Description
float angle

The angle to convert to a vector

float magnitude

The magnitude of the final vector

Returns
Type Description
Vector2

The vector that points in the direction of the angle

| Edit this page View Source

FlipW(Vector4)

Flips the W component of a UnityEngine.Vector4 while keeping the X, Y, and Z components unchanged.

Declaration
public static Vector4 FlipW(this Vector4 v)
Parameters
Type Name Description
Vector4 v

The input UnityEngine.Vector4.

Returns
Type Description
Vector4

A new UnityEngine.Vector4 with the W component flipped.

| Edit this page View Source

FlipX(Vector2)

Flips the X component of a UnityEngine.Vector2 while keeping the Y component unchanged.

Declaration
public static Vector2 FlipX(this Vector2 v)
Parameters
Type Name Description
Vector2 v

The input UnityEngine.Vector2.

Returns
Type Description
Vector2

A new UnityEngine.Vector2 with the X component flipped.

| Edit this page View Source

FlipX(Vector3)

Flips the X component of a UnityEngine.Vector3 while keeping the Y and Z components unchanged.

Declaration
public static Vector3 FlipX(this Vector3 v)
Parameters
Type Name Description
Vector3 v

The input UnityEngine.Vector3.

Returns
Type Description
Vector3

A new UnityEngine.Vector3 with the X component flipped.

| Edit this page View Source

FlipX(Vector4)

Flips the X component of a UnityEngine.Vector4 while keeping the Y, Z, and W components unchanged.

Declaration
public static Vector4 FlipX(this Vector4 v)
Parameters
Type Name Description
Vector4 v

The input UnityEngine.Vector4.

Returns
Type Description
Vector4

A new UnityEngine.Vector4 with the X component flipped.

| Edit this page View Source

FlipY(Vector2)

Flips the Y component of a UnityEngine.Vector2 while keeping the X component unchanged.

Declaration
public static Vector2 FlipY(this Vector2 v)
Parameters
Type Name Description
Vector2 v

The input UnityEngine.Vector2.

Returns
Type Description
Vector2

A new UnityEngine.Vector2 with the Y component flipped.

| Edit this page View Source

FlipY(Vector3)

Flips the Y component of a UnityEngine.Vector3 while keeping the X and Z components unchanged.

Declaration
public static Vector3 FlipY(this Vector3 v)
Parameters
Type Name Description
Vector3 v

The input UnityEngine.Vector3.

Returns
Type Description
Vector3

A new UnityEngine.Vector3 with the Y component flipped.

| Edit this page View Source

FlipY(Vector4)

Flips the Y component of a UnityEngine.Vector4 while keeping the X, Z, and W components unchanged.

Declaration
public static Vector4 FlipY(this Vector4 v)
Parameters
Type Name Description
Vector4 v

The input UnityEngine.Vector4.

Returns
Type Description
Vector4

A new UnityEngine.Vector4 with the Y component flipped.

| Edit this page View Source

FlipZ(Vector3)

Flips the Z component of a UnityEngine.Vector3 while keeping the X and Y components unchanged.

Declaration
public static Vector3 FlipZ(this Vector3 v)
Parameters
Type Name Description
Vector3 v

The input UnityEngine.Vector3.

Returns
Type Description
Vector3

A new UnityEngine.Vector3 with the Z component flipped.

| Edit this page View Source

FlipZ(Vector4)

Flips the Z component of a UnityEngine.Vector4 while keeping the X, Y, and W components unchanged.

Declaration
public static Vector4 FlipZ(this Vector4 v)
Parameters
Type Name Description
Vector4 v

The input UnityEngine.Vector4.

Returns
Type Description
Vector4

A new UnityEngine.Vector4 with the Z component flipped.

| Edit this page View Source

GetAngleBetween(Vector3, Vector3)

Gets the angle (in degrees) between two vectors

Declaration
public static float GetAngleBetween(this Vector3 Source, Vector3 Destination)
Parameters
Type Name Description
Vector3 Source

The first angle

Vector3 Destination

The second angle

Returns
Type Description
float

Returns the angle between the two vectors

| Edit this page View Source

RadiansToVector(float, float)

Converts an angle (in radians) into a vector

Declaration
public static Vector3 RadiansToVector(float radiansAngle, float magnitude = 1)
Parameters
Type Name Description
float radiansAngle

The angle to convert into a vector

float magnitude

The magnitude of the final vector

Returns
Type Description
Vector3

Returns a vector that points in the direction of the angle

| Edit this page View Source

RandomInRange(Vector2)

Declaration
public static float RandomInRange(this Vector2 range)
Parameters
Type Name Description
Vector2 range
Returns
Type Description
float
| Edit this page View Source

VectorToDegrees(Vector2)

Converts a vector into an angle (in degrees)

Declaration
public static float VectorToDegrees(this Vector2 vector)
Parameters
Type Name Description
Vector2 vector

The vector to convert

Returns
Type Description
float

Returns an angle that points in the direction of the vector

| Edit this page View Source

VectorToDegrees(Vector3)

Converts a vector into an angle (in degrees)

Declaration
public static float VectorToDegrees(this Vector3 vector)
Parameters
Type Name Description
Vector3 vector

The vector to convert

Returns
Type Description
float

Returns an angle that points in the direction of the vector

| Edit this page View Source

VectorToRadians(Vector2)

Converts a vector into an angle (in radians)

Declaration
public static float VectorToRadians(this Vector2 vector)
Parameters
Type Name Description
Vector2 vector

The vector to convert

Returns
Type Description
float

Returns an angle that points in the direction of the vector

| Edit this page View Source

VectorToRadians(Vector3)

Converts a vector into an angle (in radians)

Declaration
public static float VectorToRadians(this Vector3 vector)
Parameters
Type Name Description
Vector3 vector

The vector to convert

Returns
Type Description
float

Returns an angle that points in the direction of the vector

| Edit this page View Source

With(Color, float, float, float, float)

Creates a new UnityEngine.Color based on the input color, with optional modifications to specific color components.

Declaration
public static Color With(this Color c, float r = NaN, float g = NaN, float b = NaN, float a = NaN)
Parameters
Type Name Description
Color c

The input UnityEngine.Color to start with.

float r

The new value for the red component. If not specified (or set to NaN), the red component remains unchanged.

float g

The new value for the green component. If not specified (or set to NaN), the green component remains unchanged.

float b

The new value for the blue component. If not specified (or set to NaN), the blue component remains unchanged.

float a

The new value for the alpha (transparency) component. If not specified (or set to NaN), the alpha component remains unchanged.

Returns
Type Description
Color

A new UnityEngine.Color based on the input color with optional modifications.

| Edit this page View Source

With(Vector2, float, float)

Takes an existing vector, and a returns a new one with some fields modified

Declaration
public static Vector2 With(this Vector2 v, float x = NaN, float y = NaN)
Parameters
Type Name Description
Vector2 v

The vector to base the new one from

float x

The new x-value. If left at NaN, the field will be left unchanged

float y

The new y-value. If left at NaN, the field will be left unchanged

Returns
Type Description
Vector2

Returns a new vector with the modified fields

| Edit this page View Source

With(Vector3, float, float, float)

Takes an existing vector, and a returns a new one with some fields modified

Declaration
public static Vector3 With(this Vector3 v, float x = NaN, float y = NaN, float z = NaN)
Parameters
Type Name Description
Vector3 v

The vector to base the new one from

float x

The new x-value. If left at NaN, the field will be left unchanged

float y

The new y-value. If left at NaN, the field will be left unchanged

float z

The new z-value. If left at NaN, the field will be left unchanged

Returns
Type Description
Vector3

Returns a new vector with the modified fields

| Edit this page View Source

With(Vector4, float, float, float, float)

Takes an existing vector, and a returns a new one with some fields modified

Declaration
public static Vector4 With(this Vector4 v, float x = NaN, float y = NaN, float z = NaN, float w = NaN)
Parameters
Type Name Description
Vector4 v

The vector to base the new one from

float x

The new x-value. If left at NaN, the field will be left unchanged

float y

The new y-value. If left at NaN, the field will be left unchanged

float z

The new z-value. If left at NaN, the field will be left unchanged

float w

The new w-value. If left at NaN, the field will be left unchanged

Returns
Type Description
Vector4

Returns a new vector with the modified fields

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Generated by DocFX
☀
☾