You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
using System;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
|
|
public static class QExtensions
|
|
{
|
|
public static TStruct[] ToStructArray<TStruct>(this IntPtr ptr, int count)
|
|
{
|
|
if (ptr == IntPtr.Zero)
|
|
return null;
|
|
|
|
TStruct[] result = new TStruct[count];
|
|
int size = Marshal.SizeOf<TStruct>();
|
|
IntPtr current = ptr;
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
result[i] = Marshal.PtrToStructure<TStruct>(current);
|
|
current = IntPtr.Add(current, size);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static int[] ToIntArray(this IntPtr ptr, int count)
|
|
{
|
|
if (ptr == IntPtr.Zero)
|
|
return null;
|
|
|
|
int[] result = new int[count];
|
|
Marshal.Copy(ptr, result, 0, count);
|
|
return result;
|
|
}
|
|
|
|
public static Vector3 ToVector2(this QVec2 vec)
|
|
{
|
|
return new Vector2(vec.x, vec.y);
|
|
}
|
|
|
|
public static Vector3 ToVector3(this QVec3 vec)
|
|
{
|
|
return new Vector3(vec.x, vec.y, vec.z);
|
|
}
|
|
|
|
public static Vector3 ToVector3(this QTriVertex triVertex)
|
|
{
|
|
byte[] v = triVertex.v;
|
|
return new Vector3(v[0], v[1], v[2]);
|
|
}
|
|
}
|