-
-
Notifications
You must be signed in to change notification settings - Fork 252
/
Copy pathCollectionWrapper.cs
53 lines (48 loc) · 1.23 KB
/
CollectionWrapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using MyBox.Internal;
namespace MyBox
{
/// <summary>
/// CollectionWrapper used to apply custom drawers to Array fields
/// </summary>
[Serializable]
public class CollectionWrapper<T> : CollectionWrapperBase
{
public T[] Value;
}
/// <summary>
/// CollectionWrapper used to apply custom drawers to List fields
/// </summary>
[Serializable]
public class CollectionWrapperList<T> : CollectionWrapperBase
{
public List<T> Value = new List<T>();
}
}
namespace MyBox.Internal
{
[Serializable]
public class CollectionWrapperBase {}
}
#if UNITY_EDITOR
namespace MyBox.Internal
{
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(CollectionWrapperBase), true)]
public class CollectionWrapperDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var collection = property.FindPropertyRelative("Value");
return EditorGUI.GetPropertyHeight(collection, true);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var collection = property.FindPropertyRelative("Value");
EditorGUI.PropertyField(position, collection, label, true);
}
}
}
#endif