public void GroupToDictionary_WithNonEmptyEnumerableAndIdentifyFunction_ExpectsDictionaryOfSingles()
        {
            var dictionary = ENMRBL_NON_EMPTY.GroupToDictionary(DefaultDelegates.IdentityFunction <MultiItems>());

            Equal(ENMRBL_NON_EMPTY.ToList(), dictionary.Keys);
            Utilities.AssertManySequencesEqual(
                ENMRBL_NON_EMPTY.Select(item => new[] { item }),
                dictionary.Values);
        }
Example #2
0
            public static int Comparer(object lhsObj, object rhsObj, bool sortAscending)
            {
                if (lhsObj == null && rhsObj == null)
                {
                    return(0);
                }

                if (lhsObj == null && rhsObj != null)
                {
                    return(sortAscending ? 1 : -1);
                }

                if (lhsObj != null && rhsObj == null)
                {
                    return(sortAscending ? -1 : 1);
                }

                if (!(lhsObj is SerializedProperty lhsProp) ||
                    !(rhsObj is SerializedProperty rhsProp) ||
                    lhsProp.propertyType != rhsProp.propertyType)
                {
                    return(0);
                }

                switch (lhsProp.propertyType)
                {
                case SerializedPropertyType.Enum: return(DefaultDelegates.CompareEnumHandler(lhsProp, rhsProp));

                case SerializedPropertyType.Float: return(DefaultDelegates.CompareFloatHandler(lhsProp, rhsProp));

                case SerializedPropertyType.Integer: return(DefaultDelegates.CompareIntHandler(lhsProp, rhsProp));

                case SerializedPropertyType.Color: return(DefaultDelegates.CompareColorHandler(lhsProp, rhsProp));

                case SerializedPropertyType.Boolean: return(DefaultDelegates.CompareCheckboxHandler(lhsProp, rhsProp));

                case SerializedPropertyType.Vector2: return(DefaultDelegates.CompareVector2Handler(lhsProp, rhsProp));

                case SerializedPropertyType.Vector2Int: return(DefaultDelegates.CompareVector2IntHandler(lhsProp, rhsProp));

                case SerializedPropertyType.Vector3: return(DefaultDelegates.CompareVector3Handler(lhsProp, rhsProp));

                case SerializedPropertyType.Vector3Int: return(DefaultDelegates.CompareVector3IntHandler(lhsProp, rhsProp));

                case SerializedPropertyType.Vector4: return(DefaultDelegates.CompareVector4Handler(lhsProp, rhsProp));

                case SerializedPropertyType.ObjectReference: return(DefaultDelegates.CompareReferencesHandler(lhsProp, rhsProp));
                }

                return(lhsProp.GetHashCode().CompareTo(rhsProp.GetHashCode()));
            }
Example #3
0
            public static object Drawer(Rect r, object prop)
            {
                if (!(prop is SerializedProperty sp))
                {
                    return(null);
                }

                switch (sp.propertyType)
                {
                case SerializedPropertyType.Boolean: return(DefaultDelegates.DrawCheckboxHandler(r, sp));

                case SerializedPropertyType.Quaternion: return(DefaultDelegates.DrawQuaternionHandler(r, sp));

                default: return(DefaultDelegates.DrawDefaultHandler(r, sp));
                }
            }
        private void CellGUI(Rect cellRect, SerializedPropertyItem item, int columnIndex,
                             ref RowGUIArgs args)
        {
            Profiler.BeginSample("SerializedPropertyTreeView.CellGUI");
            CenterRectUsingSingleLineHeight(ref cellRect);
            var data   = item.GetData();
            var column = (Column)multiColumnHeader.GetColumn(columnIndex);

            if (column.drawDelegate == DefaultDelegates.s_DrawName)
            {
                Profiler.BeginSample("SerializedPropertyTreeView.OnItemGUI.LabelField");
                DefaultGUI.Label(cellRect, data.Name, IsSelected(args.item.id), false);
                Profiler.EndSample();
            }
            else if (column.drawDelegate != null)
            {
                var properties = data.Properties;
                var num        = column.dependencyIndices == null ? 0 : column.dependencyIndices.Length;
                for (var i = 0; i < num; i++)
                {
                    m_ColumnsInternal[columnIndex].dependencyProps[i] = properties[column.dependencyIndices[i]];
                }
                if (args.item.id == state.lastClickedID && HasFocus() && columnIndex == multiColumnHeader.state.visibleColumns[multiColumnHeader.state.visibleColumns[0] != 0 ? 0 : 1])
                {
                    GUI.SetNextControlName(Styles.focusHelper);
                }
                var serializedProperty = data.Properties[columnIndex];
                EditorGUI.BeginChangeCheck();
                Profiler.BeginSample("SerializedPropertyTreeView.OnItemGUI.drawDelegate");
                column.drawDelegate(cellRect, serializedProperty, m_ColumnsInternal[columnIndex].dependencyProps);
                Profiler.EndSample();
                if (EditorGUI.EndChangeCheck())
                {
                    m_ChangedId = column.filter == null || !column.filter.Active()
                        ? m_ChangedId
                        : GUIUtility.keyboardControl;
                    data.Store();
                    var selection = GetSelection();
                    if (selection.Contains(data.ObjectId))
                    {
                        var list = FindRows(selection);
                        Undo.RecordObjects((from r in list
                                            select((SerializedPropertyItem)r).GetData()
                                            .SerializedObject.targetObject).ToArray(),
                                           "Modify Multiple Properties");
                        foreach (var current in list)
                        {
                            if (current.id != args.item.id)
                            {
                                var data2 =
                                    ((SerializedPropertyItem)current).GetData();
                                if (IsEditable(data2.SerializedObject.targetObject))
                                {
                                    if (column.copyDelegate != null)
                                    {
                                        column.copyDelegate(data2.Properties[columnIndex], serializedProperty);
                                    }
                                    else
                                    {
                                        DefaultDelegates.s_CopyDefault(data2.Properties[columnIndex],
                                                                       serializedProperty);
                                    }
                                    data2.Store();
                                }
                            }
                        }
                    }
                }
                Profiler.EndSample();
            }
        }
Example #5
0
        void CellGUI(Rect cellRect, SerializedPropertyItem item, int columnIndex, ref RowGUIArgs args)
        {
            Profiler.BeginSample("SerializedPropertyTreeView.CellGUI");
            CenterRectUsingSingleLineHeight(ref cellRect);
            var    ltd    = item.GetData();
            Column column = (Column)this.multiColumnHeader.GetColumn(columnIndex);

            if (column.drawDelegate == DefaultDelegates.DrawName)
            {
                // default drawing
                Profiler.BeginSample("SerializedPropertyTreeView.OnItemGUI.LabelField");
                using (new EditorGUI.DisabledScope(!ltd.activeInHierarchy))
                {
                    DefaultGUI.Label(cellRect, ltd.name, IsSelected(args.item.id), false);
                }
                Profiler.EndSample();
            }
            else if (column.drawDelegate != null)
            {
                SerializedProperty[] props = ltd.properties;
                int depcnt = column.dependencyIndices != null ? column.dependencyIndices.Length : 0;

                for (int i = 0; i < depcnt; i++)
                {
                    m_ColumnsInternal[columnIndex].dependencyProps[i] = props[column.dependencyIndices[i]];
                }

                // allow to capture tabs
                if (args.item.id == state.lastClickedID && HasFocus() && columnIndex == multiColumnHeader.state.visibleColumns[multiColumnHeader.state.visibleColumns[0] == 0 ? 1 : 0])
                {
                    GUI.SetNextControlName(Styles.focusHelper);
                }

                SerializedProperty prop = ltd.properties[columnIndex];

                EditorGUI.BeginChangeCheck();

                Profiler.BeginSample("SerializedPropertyTreeView.OnItemGUI.drawDelegate");

                column.drawDelegate(cellRect, prop, m_ColumnsInternal[columnIndex].dependencyProps);

                Profiler.EndSample();
                if (EditorGUI.EndChangeCheck())
                {
                    // if we changed a value in a filtered column we'll have to reload the table
                    m_ChangedId = ((column.filter != null) && column.filter.Active()) ? GUIUtility.keyboardControl : m_ChangedId;
                    // update all selected items if the current row was part of the selection list
                    ltd.Store();

                    var selIds = GetSelection();

                    if (selIds.Contains(ltd.objectId))
                    {
                        IList <TreeViewItem> rows = FindRows(selIds);

                        Undo.RecordObjects(rows.Select(r => ((SerializedPropertyItem)r).GetData().serializedObject.targetObject).ToArray(), "Modify Multiple Properties");

                        foreach (var r in rows)
                        {
                            if (r.id == args.item.id)
                            {
                                continue;
                            }

                            var data = ((SerializedPropertyItem)r).GetData();

                            if (!IsEditable(data.serializedObject.targetObject))
                            {
                                continue;
                            }

                            if (column.copyDelegate != null)
                            {
                                column.copyDelegate(data.properties[columnIndex], prop);
                            }
                            else
                            {
                                DefaultDelegates.CopyDefault(data.properties[columnIndex], prop);
                            }

                            data.Store();
                        }
                    }
                }
            }
            Profiler.EndSample();
        }
 public void GroupToDictionary_WithEmptyEnumerable_ExpectsEmptyDictionary()
 => Empty(ENMRBL_EMPTY.GroupToDictionary(DefaultDelegates.IdentityFunction <MultiItems>()));
 public void GroupToDictionary_WithNullEnumerable_Throws()
 => Throws <ArgumentNullException>(
     () => ENMRBL_NULL.GroupToDictionary(DefaultDelegates.IdentityFunction <MultiItems>()));
 public void GroupToDictionary_WithNullValueSelector_Throws()
 => Throws <ArgumentNullException>(
     () => ENMRBL_NON_EMPTY.GroupToDictionary <MultiItems, MultiItems, MultiItems>(
         DefaultDelegates.IdentityFunction <MultiItems>(), null));
 public void TryGetSingle_WithNonEmptyEnumerableAndTautologicalLambda_ExpectsFalse()
 => False(ENMRBL_EMPTY.TryGetSingle(DefaultDelegates.ContradictionalLambda <MultiItems>(), out _));
 public void TryGetSingle_WithEmptyEnumerable_ExpectsFalse()
 => False(ENMRBL_EMPTY.TryGetSingle(DefaultDelegates.TautologicalLambda <MultiItems>(), out _));
 public void TryGetSingle_WithNullEnumerable_Throws()
 => Throws <ArgumentNullException>(
     () => ENMRBL_NULL.TryGetSingle(DefaultDelegates.TautologicalLambda <MultiItems>(), out _));
 public void TryGetLast_WithNonEmptyEnumerableAndTautologicalLambda_ExpectsLastItem()
 {
     True(ENMRBL_NON_EMPTY.TryGetLast(DefaultDelegates.TautologicalLambda <MultiItems>(), out var lastItem));
     Equal(ENMRBL_NON_EMPTY.LastOrDefault(), lastItem);
 }
 public void TryGetFirst_WithNonEmptyEnumerableAndContradictionalLambda_ExpectsFalse()
 => False(ENMRBL_EMPTY.TryGetFirst(DefaultDelegates.ContradictionalLambda <MultiItems>(), out _));