Beispiel #1
0
        private ReorderableList CreateList(SerializedProperty listProperty, string headerTitle, bool singleClickRemove)
        {
            var list = new ReorderableList(listProperty.serializedObject
                                           , listProperty, true, true, true, true);

            list.headerHeight = HeaderHeight;
            list.footerHeight = FooterHeight;

            list.drawHeaderCallback =
                rect => { EditorGUI.LabelField(rect, headerTitle); };

            list.elementHeight = ElementHeight;

            list.drawElementCallback = (position, index, isActive, isFocused) =>
            {
                position = EditorGUIUtil.SingleLinePosition(
                    position, EditorGUIUtility.standardVerticalSpacing * 1.5f);

                var element = list.serializedProperty.GetArrayElementAtIndex(index);
                EditorGUI.PropertyField(position, element, GUIContent.none);
            };

            list.onAddCallback =
                roList => { roList.index = AddElement(roList.serializedProperty); };

            if (singleClickRemove)
            {
                list.onRemoveCallback = EditorGUIUtil.DoSingleClickRemove;
            }

            return(list);
        }
Beispiel #2
0
        public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (m_RequireLocal)
            {
                var go = EditorGUIUtil.GetReferenceObject(property, m_SearchPropertyPath, false);

                if (m_SearchInfo == null)
                {
                    m_SearchInfo = new SearchInfo();
                }

                m_SearchInfo.Update(go);
            }
            else
            {
                m_SearchInfo = null;
            }

            bool hasLabel = label != GUIContent.none;  // Must be before 'begin property'.

            label = EditorGUI.BeginProperty(position, label, property);

            Rect rect = EditorGUIUtil.SingleLinePosition(position);

            if (hasLabel)
            {
                EditorGUI.LabelField(rect, label);
            }

            var origLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 80;

            if (m_SearchInfo != null)
            {
                DrawLocal(rect, property, hasLabel);
            }
            else
            {
                DrawBasic(rect, property, hasLabel);
            }

            EditorGUIUtility.labelWidth = origLabelWidth;

            EditorGUI.EndProperty();
        }
Beispiel #3
0
        private void DrawElement(Rect position, SerializedProperty elementProperty,
                                 bool isActive, bool isFocused)
        {
            position = EditorGUIUtil.SingleLinePosition(
                position, EditorGUIUtility.standardVerticalSpacing);

            var orig = elementProperty.objectReferenceValue;

            EditorGUI.PropertyField(position, elementProperty, GUIContent.none);

            var comp = elementProperty.objectReferenceValue;

            if (comp)
            {
                if (!ValidateComponent(comp))
                {
                    elementProperty.objectReferenceValue = null;
                }

                // TODO: BUG: Fix the duplicate check.  It isn't working.
                if (orig && orig != comp)
                {
                    int count = 0;
                    for (int i = 0; i < m_ListProperty.arraySize; i++)
                    {
                        count = m_ListProperty.GetArrayElementAtIndex(i).objectReferenceValue == comp ? 1 : 0;
                    }

                    if (count > 1)
                    {
                        Debug.LogError("Duplicate objects are not allowed in list.");
                        elementProperty.objectReferenceValue = null;
                    }
                }
            }
        }