OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.render-pipelines.high-definition@6.9.0-preview / Editor / Core / Utilities / SerializedBitArray.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.Experimental.Rendering;
5
6 namespace UnityEditor.Experimental.Rendering
7 {
8     public static class SerializedBitArrayUrtilities
9     {
10         public static bool GetBitArrayAt(this SerializedProperty property, uint bitIndex)
11         {
12             const string baseTypeName = "BitArray";
13             string type = property.type;
14             uint capacity;
15             if (type.StartsWith(baseTypeName) && uint.TryParse(type.Substring(baseTypeName.Length), out capacity))
16             {
17                 switch (capacity)
18                 {
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);
25                 }
26             }
27             throw new System.ArgumentException("Trying to call Get on unknown BitArray");
28         }
29
30         public static void SetBitArrayAt(this SerializedProperty property, uint bitIndex, bool value)
31         {
32             const string baseTypeName = "BitArray";
33             string type = property.type;
34             uint capacity;
35             if (type.StartsWith(baseTypeName) && uint.TryParse(type.Substring(baseTypeName.Length), out capacity))
36             {
37                 switch (capacity)
38                 {
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;
45                 }
46             }
47             throw new System.ArgumentException("Trying to call Get on unknown BitArray");
48         }
49
50         public static uint GetBitArrayCapacity(this SerializedProperty property)
51         {
52             const string baseTypeName = "BitArray";
53             string type = property.type;
54             uint capacity;
55             if (type.StartsWith(baseTypeName) && uint.TryParse(type.Substring(baseTypeName.Length), out capacity))
56                 return capacity;
57             throw new System.ArgumentException("Trying to call Get on unknown BitArray");
58         }
59
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(
70                 bitIndex,
71                 (ulong)property.FindPropertyRelative("data1").longValue,
72                 (ulong)property.FindPropertyRelative("data2").longValue);
73         static bool Get256(this SerializedProperty property, uint bitIndex)
74             => BitArrayUtilities.Get256(
75                 bitIndex,
76                 (ulong)property.FindPropertyRelative("data1").longValue,
77                 (ulong)property.FindPropertyRelative("data2").longValue,
78                 (ulong)property.FindPropertyRelative("data3").longValue,
79                 (ulong)property.FindPropertyRelative("data4").longValue);
80
81         static void Set8(this SerializedProperty property, uint bitIndex, bool value)
82         {
83             byte versionedData = (byte)property.FindPropertyRelative("data").intValue;
84             BitArrayUtilities.Set8(bitIndex, ref versionedData, value);
85             property.FindPropertyRelative("data").intValue = versionedData;
86         }
87         static void Set16(this SerializedProperty property, uint bitIndex, bool value)
88         {
89             ushort versionedData = (ushort)property.FindPropertyRelative("data").intValue;
90             BitArrayUtilities.Set16(bitIndex, ref versionedData, value);
91             property.FindPropertyRelative("data").intValue = versionedData;
92         }
93         static void Set32(this SerializedProperty property, uint bitIndex, bool value)
94         {
95             int versionedData = property.FindPropertyRelative("data").intValue;
96             uint trueData;
97             unsafe
98             {
99                 trueData = *(uint*)(&versionedData);
100             }
101             BitArrayUtilities.Set32(bitIndex, ref trueData, value);
102             unsafe
103             {
104                 versionedData = *(int*)(&trueData);
105             }
106             property.FindPropertyRelative("data").intValue = versionedData;
107         }
108         static void Set64(this SerializedProperty property, uint bitIndex, bool value)
109         {
110             long versionedData = property.FindPropertyRelative("data").longValue;
111             ulong trueData;
112             unsafe
113             {
114                 trueData = *(ulong*)(&versionedData);
115             }
116             BitArrayUtilities.Set64(bitIndex, ref trueData, value);
117             unsafe
118             {
119                 versionedData = *(long*)(&trueData);
120             }
121             property.FindPropertyRelative("data").longValue = versionedData;
122         }
123         static void Set128(this SerializedProperty property, uint bitIndex, bool value)
124         {
125             long versionedData1 = property.FindPropertyRelative("data1").longValue;
126             long versionedData2 = property.FindPropertyRelative("data2").longValue;
127             ulong trueData1;
128             ulong trueData2;
129             unsafe
130             {
131                 trueData1 = *(ulong*)(&versionedData1);
132                 trueData2 = *(ulong*)(&versionedData2);
133             }
134             BitArrayUtilities.Set128(bitIndex, ref trueData1, ref trueData2, value);
135             unsafe
136             {
137                 versionedData1 = *(long*)(&trueData1);
138                 versionedData2 = *(long*)(&trueData2);
139             }
140             property.FindPropertyRelative("data1").longValue = versionedData1;
141             property.FindPropertyRelative("data2").longValue = versionedData2;
142         }
143         static void Set256(this SerializedProperty property, uint bitIndex, bool value)
144         {
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;
149             ulong trueData1;
150             ulong trueData2;
151             ulong trueData3;
152             ulong trueData4;
153             unsafe
154             {
155                 trueData1 = *(ulong*)(&versionedData1);
156                 trueData2 = *(ulong*)(&versionedData2);
157                 trueData3 = *(ulong*)(&versionedData3);
158                 trueData4 = *(ulong*)(&versionedData4);
159             }
160             BitArrayUtilities.Set256(bitIndex, ref trueData1, ref trueData2, ref trueData3, ref trueData4, value);
161             unsafe
162             {
163                 versionedData1 = *(long*)(&trueData1);
164                 versionedData2 = *(long*)(&trueData2);
165                 versionedData3 = *(long*)(&trueData3);
166                 versionedData4 = *(long*)(&trueData4);
167             }
168             property.FindPropertyRelative("data1").longValue = versionedData1;
169             property.FindPropertyRelative("data2").longValue = versionedData2;
170             property.FindPropertyRelative("data3").longValue = versionedData3;
171             property.FindPropertyRelative("data4").longValue = versionedData4;
172         }
173     }
174 }