1 using System.Collections;
2 using System.Collections.Generic;
4 using UnityEngine.Experimental.Rendering;
6 namespace UnityEditor.Experimental.Rendering
8 public static class SerializedBitArrayUrtilities
10 public static bool GetBitArrayAt(this SerializedProperty property, uint bitIndex)
12 const string baseTypeName = "BitArray";
13 string type = property.type;
15 if (type.StartsWith(baseTypeName) && uint.TryParse(type.Substring(baseTypeName.Length), out capacity))
19 case 8u: return property.Get8(bitIndex);
20 case 16u: return property.Get16(bitIndex);
21 case 32u: return property.Get32(bitIndex);
22 case 64u: return property.Get64(bitIndex);
23 case 128u: return property.Get128(bitIndex);
24 case 256u: return property.Get256(bitIndex);
27 throw new System.ArgumentException("Trying to call Get on unknown BitArray");
30 public static void SetBitArrayAt(this SerializedProperty property, uint bitIndex, bool value)
32 const string baseTypeName = "BitArray";
33 string type = property.type;
35 if (type.StartsWith(baseTypeName) && uint.TryParse(type.Substring(baseTypeName.Length), out capacity))
39 case 8u: property.Set8(bitIndex, value); return;
40 case 16u: property.Set16(bitIndex, value); return;
41 case 32u: property.Set32(bitIndex, value); return;
42 case 64u: property.Set64(bitIndex, value); return;
43 case 128u: property.Set128(bitIndex, value); return;
44 case 256u: property.Set256(bitIndex, value); return;
47 throw new System.ArgumentException("Trying to call Get on unknown BitArray");
50 public static uint GetBitArrayCapacity(this SerializedProperty property)
52 const string baseTypeName = "BitArray";
53 string type = property.type;
55 if (type.StartsWith(baseTypeName) && uint.TryParse(type.Substring(baseTypeName.Length), out capacity))
57 throw new System.ArgumentException("Trying to call Get on unknown BitArray");
60 static bool Get8(this SerializedProperty property, uint bitIndex)
61 => BitArrayUtilities.Get8(bitIndex, (byte)property.FindPropertyRelative("data").intValue);
62 static bool Get16(this SerializedProperty property, uint bitIndex)
63 => BitArrayUtilities.Get16(bitIndex, (ushort)property.FindPropertyRelative("data").intValue);
64 static bool Get32(this SerializedProperty property, uint bitIndex)
65 => BitArrayUtilities.Get32(bitIndex, (uint)property.FindPropertyRelative("data").intValue);
66 static bool Get64(this SerializedProperty property, uint bitIndex)
67 => BitArrayUtilities.Get64(bitIndex, (ulong)property.FindPropertyRelative("data").longValue);
68 static bool Get128(this SerializedProperty property, uint bitIndex)
69 => BitArrayUtilities.Get128(
71 (ulong)property.FindPropertyRelative("data1").longValue,
72 (ulong)property.FindPropertyRelative("data2").longValue);
73 static bool Get256(this SerializedProperty property, uint bitIndex)
74 => BitArrayUtilities.Get256(
76 (ulong)property.FindPropertyRelative("data1").longValue,
77 (ulong)property.FindPropertyRelative("data2").longValue,
78 (ulong)property.FindPropertyRelative("data3").longValue,
79 (ulong)property.FindPropertyRelative("data4").longValue);
81 static void Set8(this SerializedProperty property, uint bitIndex, bool value)
83 byte versionedData = (byte)property.FindPropertyRelative("data").intValue;
84 BitArrayUtilities.Set8(bitIndex, ref versionedData, value);
85 property.FindPropertyRelative("data").intValue = versionedData;
87 static void Set16(this SerializedProperty property, uint bitIndex, bool value)
89 ushort versionedData = (ushort)property.FindPropertyRelative("data").intValue;
90 BitArrayUtilities.Set16(bitIndex, ref versionedData, value);
91 property.FindPropertyRelative("data").intValue = versionedData;
93 static void Set32(this SerializedProperty property, uint bitIndex, bool value)
95 int versionedData = property.FindPropertyRelative("data").intValue;
99 trueData = *(uint*)(&versionedData);
101 BitArrayUtilities.Set32(bitIndex, ref trueData, value);
104 versionedData = *(int*)(&trueData);
106 property.FindPropertyRelative("data").intValue = versionedData;
108 static void Set64(this SerializedProperty property, uint bitIndex, bool value)
110 long versionedData = property.FindPropertyRelative("data").longValue;
114 trueData = *(ulong*)(&versionedData);
116 BitArrayUtilities.Set64(bitIndex, ref trueData, value);
119 versionedData = *(long*)(&trueData);
121 property.FindPropertyRelative("data").longValue = versionedData;
123 static void Set128(this SerializedProperty property, uint bitIndex, bool value)
125 long versionedData1 = property.FindPropertyRelative("data1").longValue;
126 long versionedData2 = property.FindPropertyRelative("data2").longValue;
131 trueData1 = *(ulong*)(&versionedData1);
132 trueData2 = *(ulong*)(&versionedData2);
134 BitArrayUtilities.Set128(bitIndex, ref trueData1, ref trueData2, value);
137 versionedData1 = *(long*)(&trueData1);
138 versionedData2 = *(long*)(&trueData2);
140 property.FindPropertyRelative("data1").longValue = versionedData1;
141 property.FindPropertyRelative("data2").longValue = versionedData2;
143 static void Set256(this SerializedProperty property, uint bitIndex, bool value)
145 long versionedData1 = property.FindPropertyRelative("data1").longValue;
146 long versionedData2 = property.FindPropertyRelative("data2").longValue;
147 long versionedData3 = property.FindPropertyRelative("data3").longValue;
148 long versionedData4 = property.FindPropertyRelative("data4").longValue;
155 trueData1 = *(ulong*)(&versionedData1);
156 trueData2 = *(ulong*)(&versionedData2);
157 trueData3 = *(ulong*)(&versionedData3);
158 trueData4 = *(ulong*)(&versionedData4);
160 BitArrayUtilities.Set256(bitIndex, ref trueData1, ref trueData2, ref trueData3, ref trueData4, value);
163 versionedData1 = *(long*)(&trueData1);
164 versionedData2 = *(long*)(&trueData2);
165 versionedData3 = *(long*)(&trueData3);
166 versionedData4 = *(long*)(&trueData4);
168 property.FindPropertyRelative("data1").longValue = versionedData1;
169 property.FindPropertyRelative("data2").longValue = versionedData2;
170 property.FindPropertyRelative("data3").longValue = versionedData3;
171 property.FindPropertyRelative("data4").longValue = versionedData4;