Guest User

Untitled

a guest
May 24th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. using Unity.Collections;
  2. using Unity.Collections.LowLevel.Unsafe;
  3. using UnityEngine;
  4.  
  5. public class RefTest2 : MonoBehaviour
  6. {
  7. struct Data
  8. {
  9. public float value;
  10. }
  11.  
  12. unsafe void Start()
  13. {
  14. NativeArray<Data> array = new NativeArray<Data>(10, Allocator.Temp);
  15.  
  16. for(int i=0; i<10; i++)
  17. Do(ref UnsafeUtilityEx.ArrayElementAsRef<Data>(array.GetUnsafePtr(), i));
  18.  
  19. foreach (var element in array)
  20. {
  21. Debug.LogFormat("{0:00.0}", element.value);
  22. }
  23.  
  24. array.Dispose();
  25. }
  26.  
  27. void Do(ref Data data)
  28. {
  29. data.value = Random.Range(0f, 10f);
  30.  
  31. }
  32. }
Add Comment
Please, Sign In to add comment