Example #1
0
        public void Draw(GUIContent label, Rect r, Rect visibleArea, string tooltip, bool includeChildren)
        {
            r.xMin += EditorGUI.indent;
            var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();

            m_IsNotInPrefabContextModeWithOverrides = prefabStage == null || prefabStage.mode != PrefabStage.Mode.InContext || !PrefabStage.s_PatchAllOverriddenProperties ||
                                                      Selection.objects.All(obj => PrefabUtility.IsPartOfAnyPrefab(obj) && !AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(obj)).Equals(AssetDatabase.AssetPathToGUID(prefabStage.assetPath)));
            m_ReorderableList.draggable = m_Reorderable && m_IsNotInPrefabContextModeWithOverrides;

            Rect headerRect = new Rect(r.x, r.y, r.width, m_HeaderHeight);
            Rect sizeRect   = new Rect(headerRect.xMax - Constants.kArraySizeWidth - EditorGUI.indent * EditorGUI.indentLevel, headerRect.y,
                                       Constants.kArraySizeWidth + EditorGUI.indent * EditorGUI.indentLevel, m_HeaderHeight);

            Event     evt      = Event.current;
            EventType prevType = evt.type;

            if (!string.IsNullOrEmpty(tooltip) && prevType == EventType.Repaint)
            {
                bool hovered = headerRect.Contains(evt.mousePosition);

                if (hovered && GUIClip.visibleRect.Contains(evt.mousePosition))
                {
                    if (!GUIStyle.IsTooltipActive(tooltip))
                    {
                        s_ToolTipRect = new Rect(evt.mousePosition, Vector2.zero);
                    }
                    GUIStyle.SetMouseTooltip(tooltip, s_ToolTipRect);
                }
            }
            if (Event.current.type == EventType.MouseUp && sizeRect.Contains(Event.current.mousePosition))
            {
                Event.current.type = EventType.Used;
            }

            EditorGUI.BeginChangeCheck();
            if (!m_OriginalProperty.hasMultipleDifferentValues)
            {
                EditorGUI.BeginProperty(headerRect, GUIContent.none, m_OriginalProperty);
            }

            bool prevEnabled = GUI.enabled;

            GUI.enabled         = true;
            Property.isExpanded = EditorGUI.BeginFoldoutHeaderGroup(headerRect, Property.isExpanded, label ?? GUIContent.Temp(Property.displayName));
            EditorGUI.EndFoldoutHeaderGroup();
            GUI.enabled = prevEnabled;

            if (!m_OriginalProperty.hasMultipleDifferentValues)
            {
                EditorGUI.EndProperty();
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (Event.current.alt)
                {
                    EditorGUI.SetExpandedRecurse(Property, Property.isExpanded);
                }

                m_ReorderableList.ClearCacheRecursive();
            }

            DrawChildren(r, headerRect, sizeRect, visibleArea, prevType);
        }
Example #2
0
        public void Draw(Rect r, Rect visibleArea)
        {
            var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();

            m_IsNotInPrefabContextModeWithOverrides = prefabStage == null || prefabStage.mode != PrefabStage.Mode.InContext || !PrefabStage.s_PatchAllOverriddenProperties ||
                                                      Selection.objects.All(obj => PrefabUtility.IsPartOfAnyPrefab(obj) && !AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(obj)).Equals(AssetDatabase.AssetPathToGUID(prefabStage.assetPath)));
            m_ReorderableList.draggable = m_Reorderable && m_IsNotInPrefabContextModeWithOverrides;

            Rect headerRect = new Rect(r.x, r.y, r.width, m_HeaderHeight);
            Rect sizeRect   = new Rect(headerRect.xMax - Constants.kArraySizeWidth, headerRect.y,
                                       Constants.kArraySizeWidth, m_HeaderHeight);

            EventType prevType = Event.current.type;

            if (Event.current.type == EventType.MouseUp && sizeRect.Contains(Event.current.mousePosition))
            {
                Event.current.type = EventType.Used;
            }

            EditorGUI.BeginChangeCheck();
            m_Foldout = EditorGUI.BeginFoldoutHeaderGroup(headerRect, m_Foldout, m_Header);
            EditorGUI.EndFoldoutHeaderGroup();
            if (EditorGUI.EndChangeCheck())
            {
                m_ReorderableList.ClearCacheRecursive();
            }

            if (Event.current.type == EventType.Used && sizeRect.Contains(Event.current.mousePosition))
            {
                Event.current.type = prevType;
            }

            EditorGUI.DefaultPropertyField(sizeRect, m_ArraySize, GUIContent.none);
            EditorGUI.LabelField(sizeRect, new GUIContent("", "Array Size"));

            if (headerRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)
                {
                    Object[] objReferences = DragAndDrop.objectReferences;
                    foreach (var o in objReferences)
                    {
                        if (EditorGUI.ValidateObjectFieldAssignment(new[] { o }, typeof(Object), m_ReorderableList.serializedProperty,
                                                                    EditorGUI.ObjectFieldValidatorOptions.None) != null)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                        }
                        else
                        {
                            continue;
                        }

                        if (Event.current.type == EventType.DragPerform)
                        {
                            ReorderableList.defaultBehaviours.DoAddButton(m_ReorderableList, o);
                        }
                    }
                    DragAndDrop.AcceptDrag();
                    Event.current.Use();
                }
            }

            if (Event.current.type == EventType.DragExited)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.None;
                Event.current.Use();
            }

            if (m_Foldout)
            {
                r.y      += m_HeaderHeight + Constants.kHeaderPadding;
                r.height -= m_HeaderHeight + Constants.kHeaderPadding;

                visibleArea.y -= r.y;
                m_ReorderableList.DoList(r, visibleArea);
            }
        }