using System; using System.Collections.Generic; using System.Reflection; using Unity.VisualScripting.Dependencies.NCalc; using UnityEngine; using static UnityEngine.Rendering.DebugUI; namespace Assets.Scripts.Helpers { internal static class VectorHelper { /// /// Will get a float array for a given vector3 value /// /// /// float[x,y,z] 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; } /// /// Will get a vector3 for a given float array value /// /// /// Vector3 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; } /// /// Will get a float array for a given vector2 value /// /// /// float[x,y] public static float[] ConvertToFloatArray(this Vector2 value) { float[] result = new float[2]; result[0] = value.x; result[1] = value.y; return result; } /// /// Will get a vector2 for a given float array value /// /// /// Vector2 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; } /// /// Will get a float array for a given vector2 value /// /// /// float[x,y] public static List ConvertToListIntArray(this List value) { List result = new List(); for (int i = 0; i < value.Count; i++) { int[] intVector = new int[2]; intVector[0] = value[i].x; intVector[1] = value[i].y; result.Add(intVector); } return result; } /// /// Will get a vector2 for a given float array value /// /// /// Vector2 public static List ConvertToVector3Int(this List value) { List result = new List(); if (value != null && value.Count > 0) { for (int i = 0; i < value.Count; i++) { Vector3Int vector = new Vector3Int(); vector.x = value[0][0]; vector.y = value[0][1]; result.Add(vector); } } return result; } public static Vector3Int ConvertToVector3Int(this int[] value) { Vector3Int result = new Vector3Int(); switch (value.Length) { case 2: result.x = value[0]; result.y = value[1]; break; case 3: result.x = value[0]; result.y = value[1]; result.z = value[2]; break; default: Debug.Assert(false, "ConvertToVector3Int() got wrong array size, expected size is 2 or 3. recieved size: " + value.Length); break; } return result; } public static string ToRangeString(this Vector2 vector) { if (vector.x == vector.y) { return $"{vector.x}"; } return $"{vector.x}-{vector.y}"; } } }