@@ -11,7 +11,7 @@ public static class GenericPropertyDrawer
11
11
private const string DefaultErrorLabelText = "Type is not drawable! Please implement property drawer" ;
12
12
private const string NullPropertyText = "SerializedProperty is null. Your custom type is probably missing the [Serializable] attribute" ;
13
13
14
- public static void DrawPropertyDrawerNew ( Rect rect , SerializedProperty property , Type type , bool drawLabel = true )
14
+ public static void DrawPropertyDrawer ( Rect rect , SerializedProperty property , Type type , bool drawLabel = true )
15
15
{
16
16
if ( property == null )
17
17
{
@@ -34,10 +34,10 @@ public static void DrawPropertyDrawerNew(Rect rect, SerializedProperty property,
34
34
{
35
35
PropertyDrawIterator iter = new PropertyDrawIterator ( rect , property . Copy ( ) , drawLabel ) ;
36
36
37
- DrawPropertyDrawerNewInternal ( iter ) ;
37
+ DrawPropertyDrawerInternal ( iter ) ;
38
38
}
39
39
}
40
- public static void DrawPropertyDrawerLayoutNew ( SerializedProperty property , Type type , bool drawLabel = true )
40
+ public static void DrawPropertyDrawerLayout ( SerializedProperty property , Type type , bool drawLabel = true )
41
41
{
42
42
if ( property == null )
43
43
{
@@ -60,10 +60,10 @@ public static void DrawPropertyDrawerLayoutNew(SerializedProperty property, Type
60
60
{
61
61
PropertyDrawIteratorLayout iter = new PropertyDrawIteratorLayout ( property . Copy ( ) , drawLabel ) ;
62
62
63
- DrawPropertyDrawerNewInternal ( iter ) ;
63
+ DrawPropertyDrawerInternal ( iter ) ;
64
64
}
65
65
}
66
- private static void DrawPropertyDrawerNewInternal ( IPropertyDrawIterator iter )
66
+ private static void DrawPropertyDrawerInternal ( IPropertyDrawIterator iter )
67
67
{
68
68
do
69
69
{
@@ -100,302 +100,5 @@ public static float GetHeight(SerializedProperty property, Type type)
100
100
return spacing + elementHeights ;
101
101
}
102
102
}
103
-
104
- //private class Iterator
105
- //{
106
- // public Iterator(SerializedProperty property)
107
- // {
108
- // iterator = property.Copy();
109
- // endProperty = iterator.GetEndProperty();
110
- // }
111
-
112
- // protected readonly SerializedProperty iterator;
113
- // protected readonly SerializedProperty endProperty;
114
-
115
- // private bool consumeChildren;
116
- // private int parentDepth;
117
-
118
- // public bool Next()
119
- // {
120
- // bool nextVisible = iterator.NextVisible(true);
121
- // bool canDraw = CanDraw();
122
-
123
- // if (nextVisible)
124
- // {
125
- // if (consumeChildren)
126
- // {
127
- // ConsumeSingleLineFields(parentDepth);
128
- // consumeChildren = false;
129
- // }
130
-
131
- // int depth = iterator.depth;
132
- // if (IsSingleLine(iterator))
133
- // {
134
- // parentDepth = depth;
135
- // consumeChildren = true;
136
- // }
137
- // }
138
-
139
- // return nextVisible && canDraw;
140
- // }
141
-
142
- // public virtual void End()
143
- // {
144
-
145
- // }
146
- // private bool CanDraw()
147
- // {
148
- // return !SerializedProperty.EqualContents(iterator, endProperty);
149
- // }
150
- // private void ConsumeSingleLineFields(int depth)
151
- // {
152
- // do
153
- // {
154
- // iterator.Next(true);
155
- // } while (iterator.depth != depth);
156
- // }
157
- // private bool IsSingleLine(SerializedProperty property)
158
- // {
159
- // switch (property.propertyType)
160
- // {
161
- // case SerializedPropertyType.Vector3:
162
- // case SerializedPropertyType.Vector2:
163
- // case SerializedPropertyType.Vector3Int:
164
- // case SerializedPropertyType.Vector2Int:
165
- // case SerializedPropertyType.Vector4:
166
- // case SerializedPropertyType.Quaternion:
167
- // case SerializedPropertyType.Rect:
168
- // case SerializedPropertyType.RectInt:
169
- // case SerializedPropertyType.Bounds:
170
- // case SerializedPropertyType.BoundsInt:
171
- // return true;
172
- // }
173
-
174
- // return false;
175
- // }
176
- //}
177
- //private class DrawIterator : Iterator
178
- //{
179
- // public DrawIterator(Rect rect, SerializedProperty property, bool drawLabel) : base(property)
180
- // {
181
- // this.drawLabel = drawLabel;
182
- // this.rect = rect;
183
- // this.rect.height = EditorGUIUtility.singleLineHeight;
184
- // startIndentLevel = EditorGUI.indentLevel;
185
- // startDepth = iterator.depth;
186
- // }
187
-
188
- // private readonly bool drawLabel;
189
- // private readonly int startIndentLevel;
190
-
191
- // private int startDepth;
192
- // private Rect rect;
193
-
194
-
195
- // public void Draw()
196
- // {
197
- // EditorGUI.indentLevel = GetIndent(iterator.depth);
198
-
199
- // if (IsCustom(iterator))
200
- // {
201
- // DrawHeader();
202
- // }
203
- // else
204
- // {
205
- // DrawValue();
206
- // }
207
-
208
- // rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
209
- // }
210
-
211
-
212
- // public override void End()
213
- // {
214
- // base.End();
215
-
216
- // EditorGUI.indentLevel = startIndentLevel;
217
- // }
218
- // private void DrawHeader()
219
- // {
220
- // EditorGUI.LabelField(rect, iterator.displayName);
221
- // }
222
- // private void DrawValue()
223
- // {
224
- // if (drawLabel)
225
- // {
226
- // EditorGUI.PropertyField(rect, iterator);
227
- // }
228
- // else
229
- // {
230
- // EditorGUI.PropertyField(rect, iterator, GUIContent.none);
231
- // }
232
- // }
233
-
234
- // private int GetIndent(int depth)
235
- // {
236
- // // Depth starts at 1, whereas indent starts at 0. So we subtract 1
237
- // return startIndentLevel + (depth - startDepth) - 1;
238
- // }
239
- // private Rect GetFieldRect()
240
- // {
241
- // return new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
242
- // }
243
- // private void NextLine()
244
- // {
245
- // rect.y += EditorGUIUtility.singleLineHeight * 3;
246
- // }
247
-
248
-
249
- // private bool IsCustom(SerializedProperty property)
250
- // {
251
- // return property.propertyType == SerializedPropertyType.Generic;
252
- // }
253
- //}
254
-
255
-
256
-
257
- public static void DrawPropertyDrawer ( Rect rect , GUIContent label , Type type , SerializedProperty property , GUIContent errorLabel )
258
- {
259
- if ( errorLabel == GUIContent . none )
260
- errorLabel = GetDefaultErrorLabel ( ) ;
261
-
262
- if ( IsDrawable ( type ) )
263
- {
264
- //Unity doesn't like it when you have scene objects on assets,
265
- //so we do some magic to display it anyway
266
- if ( typeof ( Object ) . IsAssignableFrom ( type )
267
- && ! EditorUtility . IsPersistent ( property . objectReferenceValue )
268
- && property . objectReferenceValue != null )
269
- {
270
- using ( new EditorGUI . DisabledGroupScope ( true ) )
271
- {
272
- EditorGUI . ObjectField ( rect , label , property . objectReferenceValue , type , false ) ;
273
- }
274
- }
275
- else if ( TryDrawBuiltinType ( rect , label , type , property ) )
276
- {
277
- }
278
- else
279
- {
280
- EditorGUI . PropertyField ( rect , property , label ) ;
281
- }
282
- }
283
- else
284
- {
285
- EditorGUI . LabelField ( rect , errorLabel ) ;
286
- }
287
- }
288
-
289
- private static bool TryDrawBuiltinType ( Rect rect , GUIContent label , Type type , SerializedProperty property )
290
- {
291
- if ( typeof ( Color ) . IsAssignableFrom ( type ) )
292
- {
293
- EditorGUI . ColorField ( rect , property . colorValue ) ;
294
- return true ;
295
- }
296
- else if ( typeof ( AnimationCurve ) . IsAssignableFrom ( type ) )
297
- {
298
- EditorGUI . CurveField ( rect , property . animationCurveValue ) ;
299
- return true ;
300
- }
301
- else if ( typeof ( double ) . IsAssignableFrom ( type ) )
302
- {
303
- EditorGUI . DoubleField ( rect , property . doubleValue ) ;
304
- return true ;
305
- }
306
- else if ( typeof ( float ) . IsAssignableFrom ( type ) )
307
- {
308
- EditorGUI . FloatField ( rect , property . floatValue ) ;
309
- return true ;
310
- }
311
- else if ( typeof ( int ) . IsAssignableFrom ( type ) )
312
- {
313
- EditorGUI . IntField ( rect , property . intValue ) ;
314
- return true ;
315
- }
316
- else if ( typeof ( string ) . IsAssignableFrom ( type ) )
317
- {
318
- EditorGUI . TextField ( rect , property . stringValue ) ;
319
- return true ;
320
- }
321
- else if ( typeof ( long ) . IsAssignableFrom ( type ) )
322
- {
323
- EditorGUI . LongField ( rect , property . longValue ) ;
324
- return true ;
325
- }
326
- else if ( typeof ( bool ) . IsAssignableFrom ( type ) )
327
- {
328
- EditorGUI . Toggle ( rect , property . boolValue ) ;
329
- return true ;
330
- }
331
- else if ( typeof ( Vector2 ) . IsAssignableFrom ( type ) )
332
- {
333
- EditorGUI . Vector2Field ( rect , label , property . vector2Value ) ;
334
- return true ;
335
- }
336
- else if ( typeof ( Vector3 ) . IsAssignableFrom ( type ) )
337
- {
338
- EditorGUI . Vector3Field ( rect , label , property . vector3Value ) ;
339
- return true ;
340
- }
341
- else if ( typeof ( Vector4 ) . IsAssignableFrom ( type ) )
342
- {
343
- EditorGUI . Vector4Field ( rect , label , property . vector4Value ) ;
344
- return true ;
345
- }
346
- else if ( typeof ( Quaternion ) . IsAssignableFrom ( type ) )
347
- {
348
- EditorGUI . Vector4Field ( rect , label , property . quaternionValue . ToVector4 ( ) ) ;
349
- return true ;
350
- }
351
-
352
- return false ;
353
- }
354
-
355
- public static void DrawPropertyDrawerLayout ( Type type , GUIContent label , SerializedProperty property , GUIContent errorLabel )
356
- {
357
- if ( IsDrawable ( type ) )
358
- {
359
- //Unity doesn't like it when you have scene objects on assets,
360
- //so we do some magic to display it anyway
361
- if ( typeof ( Object ) . IsAssignableFrom ( type )
362
- && ! EditorUtility . IsPersistent ( property . objectReferenceValue )
363
- && property . objectReferenceValue != null )
364
- {
365
- using ( new EditorGUI . DisabledGroupScope ( true ) )
366
- {
367
- EditorGUILayout . ObjectField ( label , property . objectReferenceValue , type , false ) ;
368
- }
369
- }
370
- else if ( type . IsAssignableFrom ( typeof ( Quaternion ) ) )
371
- {
372
- Vector4 displayValue = property . quaternionValue . ToVector4 ( ) ;
373
-
374
- property . quaternionValue = EditorGUILayout . Vector4Field ( label , displayValue ) . ToQuaternion ( ) ;
375
- }
376
- else if ( type . IsAssignableFrom ( typeof ( Vector4 ) ) )
377
- {
378
- property . vector4Value = EditorGUILayout . Vector4Field ( label , property . vector4Value ) ;
379
- }
380
- else
381
- {
382
- EditorGUILayout . PropertyField ( property , label ) ;
383
- }
384
- }
385
- else
386
- {
387
- EditorGUILayout . LabelField ( errorLabel ) ;
388
- }
389
- }
390
-
391
- private static bool IsDrawable ( Type type )
392
- {
393
- return SOArchitecture_EditorUtility . HasPropertyDrawer ( type ) || typeof ( Object ) . IsAssignableFrom ( type ) || type . IsEnum ;
394
- }
395
-
396
- private static GUIContent GetDefaultErrorLabel ( )
397
- {
398
- return new GUIContent ( DefaultErrorLabelText ) ;
399
- }
400
103
}
401
104
}
0 commit comments