ソースコード
using Unity.Collections;
namespace Kogane
{
public static class NativeListExtensionMethods
{
public static void Reverse<T>( this NativeList<T> self ) where T : unmanaged
{
var halfLength = self.Length / 2;
var i = 0;
var j = self.Length - 1;
for ( ; i < halfLength; i++, j-- )
{
( self[ i ], self[ j ] ) = ( self[ j ], self[ i ] );
}
}
}
}
使用例
using Kogane;
using Unity.Collections;
using UnityEngine;
public class Example : MonoBehaviour
{
private void Start()
{
using var list = new NativeList<int>( Allocator.Temp )
{
1,
2,
3,
};
list.Reverse();
foreach ( var x in list )
{
Debug.Log( x );
}
}
}
参考サイト様