/// <summary> /// Finds and returns the closest vector2 in an array to the given vector. /// </summary> /// <param name="arr"></param> /// <param name="comparison"></param> /// <returns></returns> public static Vector2 FindClosestVector(List <Vector2> arr, Vector2 comparison) { Vector2Struct s = ToStruct(comparison); int index = FindClosestV2(arr.ToArray(), ref s, arr.Count); return(arr[index]); }
/// <summary> /// Finds and returns the closest vector2 in an array to the given vector. /// </summary> /// <param name="arr"></param> /// <param name="comparison"></param> /// <returns></returns> public static Vector2 FindClosestVector(Vector2[] arr, Vector2 comparison) { Vector2Struct s = ToStruct(comparison); int index = FindClosestV2(arr, ref s, arr.Length); return(arr[index]); }
/// <summary> /// Returns a randomized Vector2, each property is randomized seperately between their respective passed arguments. All limits are inclusive. /// </summary> public static Vector3 GetRandomizedVector2(int minX, int maxX, int minY, int maxY) { Vector2Struct vs = new Vector2Struct(); RandomizeVector2IntRange(out vs, minX, maxX, minY, maxY); return(ToVector(vs)); }
/// <summary> /// Returns a randomized Vector2, each property is randomized seperately between min and max. /// </summary> /// <param name="min">Lower limit for randomization.(Inclusive)</param> /// <param name="max">Upper limit for randomization.(Inclusive)</param> public static Vector2 GetRandomizedVector2(int min, int max) { Vector2Struct vs = new Vector2Struct(); RandomizeVector2Int(out vs, min, max); return(ToVector(vs)); }
/// <summary> /// Returns a randomized Vector2, each property is randomized seperately between their respective passed arguments. All limits are inclusive. /// </summary> public static Vector2 GetRandomizedVector2(float minX, float maxX, float minY, float maxY) { Vector2Struct vs = new Vector2Struct(); RandomizeVector2FRange(out vs, minX, maxX, minY, maxY); return(ToVector(vs)); }
/// <summary> /// Returns a Vector2Struct out of a Vector2 type value. /// </summary> /// <param name="s"></param> /// <returns></returns> private static Vector2Struct ToStruct(Vector2 v) { Vector2Struct vs = new Vector2Struct(); vs.x = v.x; vs.y = v.y; return(vs); }
/// <summary> /// Returns a Vector2 out of a Vector2Struct type value. /// </summary> /// <param name="s"></param> /// <returns></returns> private static Vector2 ToVector(Vector2Struct s) { Vector2 v = new Vector2(); v.x = (float)s.x; v.y = (float)s.y; return(v); }
/// <summary> /// Returns a pointer pointing to the first element of dynamically allocated array which contains given amount of points between the start & end points. /// </summary> public static Vector2[] GetPointsBetweenVectors(Vector2 start, Vector2 end, int size) { // Return if size is 0 or neg. if (size < 1) { Debug.LogError("Size of the required array can not be smaller than 1."); return(null); } // Init structs. Vector2Struct vS = ToStruct(start); Vector2Struct vE = ToStruct(end); // The method will return the pointer pointing to the beginning address of the allocated & calculated array. IntPtr arrayPointer = GetPointsBetweenVectorsV2(ref vS, ref vE, ref size); // Init point vectors to copy the data. Vector2[] points = new Vector2[size]; // Offset is going to be used to increment the pointer by the size of pointSize. int offset = 0; // Size of a Vector3Struct type variable in the memory. Which is blittable with the V3 struct in C++ library. int pointSize = Marshal.SizeOf(typeof(Vector2Struct)); // Increment the whole array. for (int i = 0; i < size; i++) { // Convert to structure from the pointer, which will be incremented by the size of V3 struct. Then convert the structure to Vector and assign. points[i] = ToVector((Vector2Struct)Marshal.PtrToStructure(new IntPtr(arrayPointer.ToInt32() + offset), typeof(Vector2Struct))); // Increment offset to shift the memory address forward. offset += pointSize; } // Free the memory which was allocated by C++ method. Marshal.FreeCoTaskMem(arrayPointer); return(points); }
public override void Read(IOMemoryStream ms, UAssetFile f) { //Is we're in an array, this will **ALWAYS** be a prop list struct. UStruct st; if (isArray) { structType = "(array)"; unknown = 0; st = new PropListStruct(); f.Debug("Read Array", $"====READ STRUCT BEGIN @ {ms.position} ({structType}, {unknown})====", ConsoleColor.Yellow); } else { structType = ms.ReadNameTableEntry(f); unknown = ms.ReadInt(); f.Debug("Read Array", $"====READ STRUCT BEGIN @ {ms.position} ({structType}, {unknown})====", ConsoleColor.Yellow); //Find the struct type. Unknown if real: ItemStatInfo if (structType == "ItemStatInfo" || structType == "ItemNetID" || structType == "ItemNetInfo" || structType == "Transform" || structType == "PrimalPlayerDataStruct" || structType == "PrimalPlayerCharacterConfigStruct" || structType == "PrimalPersistentCharacterStatsStruct" || structType == "TribeData" || structType == "TribeGovernment" || structType == "TerrainInfo" || structType == "ArkInventoryData" || structType == "DinoOrderGroup" || structType == "ARKDinoData") { //Open this as a struct property list. st = new PropListStruct(); } else if (structType == "Vector" || structType == "Rotator") { //3d vector or rotor st = new Vector3Struct(); } else if (structType == "Vector2D") { //2d vector st = new Vector2Struct(); } else if (structType == "Quat") { //Quat st = new QuatStruct(); } else if (structType == "Color") { //Color st = new ColorStruct(); } else if (structType == "LinearColor") { //Linear color st = new LinearColorStruct(); } else if (structType == "UniqueNetIdRepl") { //Some net stuff st = new UniqueNetIdStruct(); } else if (structType == "Guid") { //Some net stuff st = new GuidStruct(); } else if (structType == "IntPoint") { //Some net stuff st = new IntPointStruct(); } else if (structType == "StringAssetReference") { st = new StringAssetReferenceStruct(); } else { //Interpet this as a struct property list. Maybe raise a warning later? f.Warn("Struct Warning", $"Unknown type '{structType}'. Interpeting as a struct property list..."); st = new PropListStruct(); } } //Read st.ReadStruct(ms, f, this); data = st; f.Debug("Read Struct", $"====READ STRUCT END @ {ms.position}====", ConsoleColor.Yellow); }
private static extern void RandomizeVector2IntRange(out Vector2Struct vs, int minX, int maxX, int minY, int maxY);
private static extern void RandomizeVector2Int(out Vector2Struct vs, int min, int max);
private static extern void RandomizeVector2FRange(out Vector2Struct vs, double minX, double maxX, double minY, double maxY);
private static extern void RandomizeVector2F(out Vector2Struct vs, double min, double max);
private static extern IntPtr GetPointsBetweenVectorsV2(ref Vector2Struct start, ref Vector2Struct end, ref int size);
private static extern int FindClosestV2([In, Out] Vector2[] array, ref Vector2Struct comparison, int size);