using System;
|
using System.Reflection;
|
using UnityEngine;
|
using static UnityEngine.Rendering.DebugUI;
|
|
namespace Assets.Scripts.Helpers
|
{
|
internal static class VectorHelper
|
{
|
|
/// <summary>
|
/// Will get a float array for a given vector3 value
|
/// </summary>
|
/// <param name="value"></param>
|
/// <returns>float[x,y,z]</returns>
|
public static float[] ConvertToFloatArray(this Vector3 value)
|
{
|
float[] result = new float[3];
|
result[0] = value.x;
|
result[1] = value.y;
|
result[2] = value.z;
|
return result;
|
}
|
|
/// <summary>
|
/// Will get a float array for a given vector2 value
|
/// </summary>
|
/// <param name="value"></param>
|
/// <returns>float[x,y]</returns>
|
public static float[] ConvertToFloatArray(this Vector2 value)
|
{
|
float[] result = new float[2];
|
result[0] = value.x;
|
result[1] = value.y;
|
return result;
|
}
|
|
/// <summary>
|
/// Will get a vector3 for a given float array value
|
/// </summary>
|
/// <param name="value"></param>
|
/// <returns>Vector3</returns>
|
public static Vector3 ConvertToVector3(this float[] floats)
|
{
|
Vector3 result = new Vector3();
|
if (floats != null && floats.Length == 3)
|
{
|
result.x = floats[0];
|
result.y = floats[1];
|
result.z = floats[2];
|
}
|
else
|
{
|
Debug.Log("Can't convert float[] to Vector3, did not conform to float[] with 3 values (x,y,z)");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// Will get a vector2 for a given float array value
|
/// </summary>
|
/// <param name="value"></param>
|
/// <returns>Vector2</returns>
|
public static Vector2 ConvertToVector2(this float[] floats)
|
{
|
Vector3 result = new Vector3();
|
if (floats != null && floats.Length == 2)
|
{
|
result.x = floats[0];
|
result.y = floats[1];
|
}
|
else
|
{
|
Debug.Log("Can't convert float[] to Vector2, did not conform to float[] with 2 values (x,y)");
|
}
|
return result;
|
}
|
}
|
}
|