Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created May 20, 2018 04:19
Show Gist options
  • Save tsubaki/43a23a8482f3a5dcba26515ae1d4b310 to your computer and use it in GitHub Desktop.
Save tsubaki/43a23a8482f3a5dcba26515ae1d4b310 to your computer and use it in GitHub Desktop.
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
public class RefTest2 : MonoBehaviour
{
struct Data
{
public float value;
}
unsafe void Start()
{
NativeArray<Data> array = new NativeArray<Data>(10, Allocator.Temp);
for(int i=0; i<10; i++)
Do(ref UnsafeUtilityEx.ArrayElementAsRef<Data>(array.GetUnsafePtr(), i));
foreach (var element in array)
{
Debug.LogFormat("{0:00.0}", element.value);
}
array.Dispose();
}
void Do(ref Data data)
{
data.value = Random.Range(0f, 10f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment