public static int TestChangeArray(ref UdkDynamicArray wrapper) { var source = new Vector3[2]; source[0] = new Vector3() {X = 1, Y = 2, Z = 3}; source[1] = new Vector3() { X = 4, Y = 5, Z = 6 }; int floatsLength = 3*source.Length; var outputArray = new float[floatsLength]; for (int i = 0; i < source.Length; i++) { outputArray[i * 3 + 0] = (float) source[i].X; outputArray[i * 3 + 1] = (float)source[i].Y; outputArray[i * 3 + 2] = (float)source[i].Z; } //wrapper.DataPtr = Marshal.AllocHGlobal(sizeof(float) * floatsLength); Marshal.Copy(outputArray, 0, wrapper.DataPtr, floatsLength); //wrapper.Count = source.Length; //wrapper.MaxSize = source.Length; //ha ha ha here we have managedArray passed from UDK return 123;//managedArray.Length; }
public static int TestSendArray(ref UdkDynamicArray wrapper) { int valuesCount = wrapper.Count * 5; //*4 => 1 int point type + 3 float from Vector struct var intArr = new int[valuesCount]; var floatArr = new float[valuesCount]; //int and floats are assumed to be both of 32 bits (but it is not everywhere true) Marshal.Copy(wrapper.DataPtr, intArr, 0, valuesCount); Marshal.Copy(wrapper.DataPtr, floatArr, 0, valuesCount); var cells = new List<CellInfo>(); for (int i = 0; i < valuesCount; i += 5) { var cell = new CellInfo(); cell.PointType = intArr[i]; cell.Direction = intArr[i + 1]; cell.Point.X = floatArr[i + 2]; cell.Point.Y = floatArr[i + 3]; cell.Point.Z = floatArr[i + 4]; cells.Add(cell); } //ha ha ha here we have managedArray passed from UDK return 123;//managedArray.Length; }