miepzerino
2025-01-20 9ac1377fd0ea4eee5606ee659662acd58634c2b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
    {
 
        /// <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 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 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 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;
        }
 
        /// <summary>
        /// Will get a float array for a given vector2 value
        /// </summary>
        /// <param name="value"></param>
        /// <returns>float[x,y]</returns>
        public static List<int[]> ConvertToListIntArray(this List<Vector3Int> value)
        {
            List<int[]> result = new List<int[]>();
            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;
        }
 
        /// <summary>
        /// Will get a vector2 for a given float array value
        /// </summary>
        /// <param name="value"></param>
        /// <returns>Vector2</returns>
        public static List<Vector3Int> ConvertToVector3Int(this List<int[]> value)
        {
            List<Vector3Int> result = new List<Vector3Int>();
            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;
        }
    }
}