mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-10 21:09:08 -05:00
NativeArrayManager.Convert
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
@@ -56,5 +57,24 @@ namespace UniGLTF
|
||||
array.CopyFrom(data);
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// サイズの違う型にコピーする。
|
||||
///
|
||||
/// 例
|
||||
/// NativeArray<ushort> => NativeArray<uint>
|
||||
/// </summary>
|
||||
public NativeArray<U> Convert<T, U>(NativeArray<T> src, Func<T, U> convert)
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
var bytes = CreateNativeArray<byte>(src.Length * Marshal.SizeOf<T>());
|
||||
var dst = bytes.Reinterpret<U>(1);
|
||||
for (int i = 0; i < src.Length; ++i)
|
||||
{
|
||||
dst[i] = convert(src[i]);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user