설명 없음
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.

Fixed2.cs 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. namespace UnityEngine.Rendering.Universal
  5. {
  6. [StructLayout(LayoutKind.Sequential)]
  7. struct Fixed2<T> where T : unmanaged
  8. {
  9. public T item1;
  10. public T item2;
  11. public Fixed2(T item1) : this(item1, item1)
  12. {
  13. }
  14. public Fixed2(T item1, T item2)
  15. {
  16. this.item1 = item1;
  17. this.item2 = item2;
  18. }
  19. public unsafe T this[int index]
  20. {
  21. get
  22. {
  23. CheckRange(index);
  24. fixed (T* items = &item1)
  25. {
  26. return items[index];
  27. }
  28. }
  29. set
  30. {
  31. CheckRange(index);
  32. fixed (T* items = &item1)
  33. {
  34. items[index] = value;
  35. }
  36. }
  37. }
  38. [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
  39. static void CheckRange(int index)
  40. {
  41. #if ENABLE_UNITY_COLLECTIONS_CHECKS
  42. if (index is < 0 or > 1)
  43. {
  44. throw new IndexOutOfRangeException($"Index {index} is out of range of 2.");
  45. }
  46. #endif
  47. }
  48. }
  49. }