27 lines
922 B
C#
27 lines
922 B
C#
using UnityEngine;
|
|
|
|
public static class MathExtensions{
|
|
public static Vector3 Flatten(this Vector3 origin, float? x = null, float? y = null, float? z = null){
|
|
return new Vector3(x ?? origin.x, y ?? origin.y, z ?? origin.z);
|
|
}
|
|
|
|
public static Quaternion Flatten(this Quaternion input, float? x = null, float? y = null, float? z = null){
|
|
return Quaternion.Euler(input.eulerAngles.Flatten(x, y, z));
|
|
}
|
|
|
|
public static Vector3 DirectionTo(this Vector3 origin, Vector3 to){
|
|
return (to - origin).normalized;
|
|
}
|
|
|
|
public static Color Alpha(this Color input, float newAlpha){
|
|
return new Color(input.r, input.g, input.b, newAlpha);
|
|
}
|
|
|
|
public static Vector2 Rotate(this Vector2 v, float delta) {
|
|
return new Vector2(
|
|
v.x * Mathf.Cos(delta) - v.y * Mathf.Sin(delta),
|
|
v.x * Mathf.Sin(delta) + v.y * Mathf.Cos(delta)
|
|
);
|
|
}
|
|
}
|