Ejemplo n.º 1
0
        private void DrawFooterCallback(Rect rect)
        {
            float xMax       = rect.xMax;
            float availWidth = xMax - 60f;
            //if the view is wide this only needs to be XMax - 300 else its Xmin
            float bgXmin = rect.xMax - 300f > rect.xMin ? rect.xMax - 300f : rect.xMin;
            Rect  bgRect = new Rect(bgXmin, rect.yMin, rect.width, rect.height);

            bgRect.xMax = rect.xMax;
            float agWidthMod = 0f;

            //If the list count is greater than 1 we need to draw the background for the aggregation controls
            if (_dnaEvaluatorList.count > 1)
            {
                agWidthMod = 4f;
            }
            rect = new Rect(availWidth, rect.y, xMax - availWidth - agWidthMod, rect.height);
            Rect rect2  = new Rect(availWidth + 4f, rect.y - 3f, 25f, 13f);
            Rect rect3  = new Rect(xMax - 33f, rect.y - 3f, 25f, 13f);
            Rect agRect = new Rect(bgRect.xMin + 8f, bgRect.yMin, (bgRect.width - rect.width) - 16f, bgRect.height);

            if (Event.current.type == EventType.Repaint)
            {
                var prevFooterFixedHeight = ROLDefaults.footerBackground.fixedHeight;
                var addMinusHeight        = prevFooterFixedHeight;
                //If the list count is greater than 1 we need to draw the background for the aggregation controls
                if (_dnaEvaluatorList.count > 1)
                {
                    //usually 13f but we need it higher to hold aggregation controls
                    ROLDefaults.footerBackground.fixedHeight = 13f + (EditorGUIUtility.standardVerticalSpacing * 3);
                    ROLDefaults.footerBackground.Draw(bgRect, false, false, false, false);
                    addMinusHeight += 2f;
                }
                //now draw the standard background for the +/- controls
                ROLDefaults.footerBackground.fixedHeight = addMinusHeight;
                ROLDefaults.footerBackground.Draw(rect, false, false, false, false);
                ROLDefaults.footerBackground.fixedHeight = prevFooterFixedHeight;
            }
            if (GUI.Button(rect2, ROLDefaults.iconToolbarPlus, ROLDefaults.preButton))
            {
                ROLDefaults.DoAddButton(_dnaEvaluatorList);
            }
            using (new EditorGUI.DisabledScope(_dnaEvaluatorList.index < 0 || _dnaEvaluatorList.index >= _dnaEvaluatorList.count))
            {
                if (GUI.Button(rect3, ROLDefaults.iconToolbarMinus, ROLDefaults.preButton))
                {
                    ROLDefaults.DoRemoveButton(_dnaEvaluatorList);
                }
            }
            var prevIndentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;
            //If the list count is greater than 1 we need to draw the background for the aggregation controls
            if (_dnaEvaluatorList.count > 1)
            {
                DrawAggregationMethod(agRect, _property);
            }
            EditorGUI.indentLevel = prevIndentLevel;
        }
Ejemplo n.º 2
0
        private void CreateReorderable(SerializedProperty property, GUIContent label)
        {
            var actionsProp = property.FindPropertyRelative("actions");
            var defaults    = new ReorderableList.Defaults();

            reorderable                     = new ReorderableList(property.serializedObject, actionsProp, false, true, true, true);
            reorderable.draggable           = true;
            reorderable.drawHeaderCallback  = rect => EditorGUI.LabelField(rect, label);
            reorderable.drawElementCallback = (rect, index, active, focused) =>
            {
                rect.y      += 2;
                rect.height -= 2;
                SerializableAction_SingleDrawer.DrawSerializableAction(
                    rect, actionsProp.GetArrayElementAtIndex(index)
                    );
            };
            reorderable.elementHeightCallback = index =>
            {
                var height = SerializableAction_SingleDrawer.FindSerializableActionHeight(
                    actionsProp.GetArrayElementAtIndex(index), GUIContent.none) + 4f;
                cachedHeights[index] = height;
                return(height);
            };
            reorderable.showDefaultBackground = true;

            reorderable.drawElementBackgroundCallback = (rect, index, active, focused) =>
            {
                var   rectHeight = EditorGUIUtility.singleLineHeight;
                float height;
                if (cachedHeights.TryGetValue(index, out height))
                {
                    rectHeight = height;
                }
                rect.height = rectHeight;

                defaults.DrawElementBackground(rect, index, active, focused, true);
            };

            reorderable.onAddCallback = list =>
            {
                defaults.DoAddButton(list);
                //If this is the first element, set the call state to the correct default. Otherwise do what the reorderable always does, which is
                //copy from the element above
                if (list.index == 0)
                {
                    var addedObj = actionsProp.GetArrayElementAtIndex(list.index);
                    addedObj.FindPropertyRelative("callState").enumValueIndex = (int)UnityEventCallState.RuntimeOnly;
                }
            };
        }