< Summary

Class:ReorderableList.Editor.ReorderableDrawer
Assembly:ReorderableEditor
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/ReorderableArray/Editor/ReorderableDrawer.cs
Covered lines:0
Uncovered lines:45
Coverable lines:45
Total lines:142
Line coverage:0% (0 of 45)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ReorderableDrawer()0%2100%
CanCacheInspectorGUI(...)0%2100%
GetPropertyHeight(...)0%6200%
OnGUI(...)0%6200%
GetListId(...)0%6200%
GetList(...)0%2100%
GetList(...)0%2100%
GetList(...)0%2100%
GetList(...)0%1321100%
SurrogateCallback(...)0%2100%
SetReference(...)0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/ReorderableArray/Editor/ReorderableDrawer.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEditor;
 3using UnityEngine;
 4
 5namespace ReorderableList.Editor
 6{
 7
 8    [CustomPropertyDrawer(typeof(ReorderableAttribute))]
 9    public class ReorderableDrawer : PropertyDrawer
 10    {
 11
 12        public const string ARRAY_PROPERTY_NAME = "array";
 13
 014        private static Dictionary<int, ReorderableList> lists = new Dictionary<int, ReorderableList>();
 15
 016        public override bool CanCacheInspectorGUI(SerializedProperty property) { return false; }
 17
 18        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 19        {
 20
 021            ReorderableList list = GetList(property, attribute as ReorderableAttribute, ARRAY_PROPERTY_NAME);
 22
 023            return list != null ? list.GetHeight() : EditorGUIUtility.singleLineHeight;
 24        }
 25
 26        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 27        {
 28
 029            ReorderableList list = GetList(property, attribute as ReorderableAttribute, ARRAY_PROPERTY_NAME);
 30
 031            if (list != null)
 32            {
 33
 034                list.DoList(EditorGUI.IndentedRect(position), label);
 035            }
 36            else
 37            {
 38
 039                GUI.Label(position, "Array must extend from ReorderableArray", EditorStyles.label);
 40            }
 041        }
 42
 43        public static int GetListId(SerializedProperty property)
 44        {
 45
 046            if (property != null)
 47            {
 48
 049                int h1 = property.serializedObject.targetObject.GetHashCode();
 050                int h2 = property.propertyPath.GetHashCode();
 51
 052                return (((h1 << 5) + h1) ^ h2);
 53            }
 54
 055            return 0;
 56        }
 57
 058        public static ReorderableList GetList(SerializedProperty property, string arrayPropertyName) { return GetList(pr
 59
 060        public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib, string arrayProp
 61
 062        public static ReorderableList GetList(SerializedProperty property, int id, string arrayPropertyName) { return Ge
 63
 64        public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib, int id, string a
 65        {
 66
 067            if (property == null)
 68            {
 69
 070                return null;
 71            }
 72
 073            ReorderableList list = null;
 074            SerializedProperty array = property.FindPropertyRelative(arrayPropertyName);
 75
 076            if (array != null && array.isArray)
 77            {
 78
 079                if (!lists.TryGetValue(id, out list))
 80                {
 81
 082                    if (attrib != null)
 83                    {
 84
 085                        Texture icon = !string.IsNullOrEmpty(attrib.elementIconPath) ? AssetDatabase.GetCachedIcon(attri
 86
 087                        ReorderableList.ElementDisplayType displayType = attrib.singleLine ? ReorderableList.ElementDisp
 88
 089                        list = new ReorderableList(array, attrib.add, attrib.remove, attrib.draggable, displayType, attr
 090                        list.paginate = attrib.paginate;
 091                        list.pageSize = attrib.pageSize;
 092                        list.sortable = attrib.sortable;
 93
 94                        //handle surrogate if any
 95
 096                        if (attrib.surrogateType != null)
 97                        {
 98
 099                            SurrogateCallback callback = new SurrogateCallback(attrib.surrogateProperty);
 100
 0101                            list.surrogate = new ReorderableList.Surrogate(attrib.surrogateType, callback.SetReference);
 102                        }
 0103                    }
 104                    else
 105                    {
 106
 0107                        list = new ReorderableList(array, true, true, true);
 108                    }
 109
 0110                    lists.Add(id, list);
 0111                }
 112                else
 113                {
 114
 0115                    list.List = array;
 116                }
 117            }
 118
 0119            return list;
 120        }
 121
 122        private struct SurrogateCallback
 123        {
 124
 125            private string property;
 126
 0127            internal SurrogateCallback(string property) { this.property = property; }
 128
 129            internal void SetReference(SerializedProperty element, Object objectReference, ReorderableList list)
 130            {
 131
 0132                SerializedProperty prop = !string.IsNullOrEmpty(property) ? element.FindPropertyRelative(property) : nul
 133
 0134                if (prop != null && prop.propertyType == SerializedPropertyType.ObjectReference)
 135                {
 136
 0137                    prop.objectReferenceValue = objectReference;
 138                }
 0139            }
 140        }
 141    }
 142}