コード例 #1
0
        private void Sort(IList <TreeViewItem> rows, int sortIdx)
        {
            Debug.Assert(sortIdx >= 0);

            SearchColumn column = Col(sortIdx);

            if (column == null)
            {
                return;
            }

            var get = column.getter;

            if (get == null)
            {
                return;
            }

            var myRows        = rows as List <TreeViewItem>;
            var sortAscending = multiColumnHeader.IsSortedAscending(sortIdx);
            var sortOrder     = sortAscending ? 1 : -1;

            var comp = column.comparer;

            if (comp == null)
            {
                if (column.getter != null)
                {
                    if (rows.Count > 0)
                    {
                        myRows.Sort((lhs, rhs) =>
                        {
                            var lhsargs = new SearchColumnEventArgs(((PropertyItem)lhs).GetData(), m_TableView.context, column);
                            var rhsargs = new SearchColumnEventArgs(((PropertyItem)rhs).GetData(), m_TableView.context, column);
                            var lhsv    = get(lhsargs);
                            if (lhsv is IComparable c)
                            {
                                return(Comparer.Default.Compare(c, get(rhsargs)) * sortOrder);
                            }
                            return(Comparer.Default.Compare(lhsv?.GetHashCode() ?? 0, get(rhsargs)?.GetHashCode() ?? 0) * sortOrder);
                        });
                    }
                }

                return;
            }

            myRows.Sort((lhs, rhs) =>
            {
                var lhsargs = new SearchColumnEventArgs(((PropertyItem)lhs).GetData(), m_TableView.context, column);
                var rhsargs = new SearchColumnEventArgs(((PropertyItem)rhs).GetData(), m_TableView.context, column);

                lhsargs.value = get(lhsargs);
                rhsargs.value = get(rhsargs);

                return(comp(new SearchColumnCompareArgs(lhsargs, rhsargs, sortAscending)) * sortOrder);
            });
        }
コード例 #2
0
        private static object GetName(SearchColumnEventArgs args)
        {
            var value = args.column.SelectValue(args.item, args.item.context ?? args.context);

            if (value is Object obj)
            {
                return(obj);
            }
            return((value ?? args.value)?.ToString());
        }
コード例 #3
0
        static object SetEnabled(SearchColumnEventArgs args)
        {
            var go = args.item.ToObject <GameObject>();

            if (!go)
            {
                return(null);
            }
            go.SetActive((bool)args.value);
            return(go.activeSelf);
        }
コード例 #4
0
 private static object DrawName(SearchColumnEventArgs args)
 {
     if (args.value is Object obj)
     {
         GUI.Label(args.rect, Utils.GUIContentTemp(obj.name, AssetPreview.GetMiniThumbnail(obj)), GetItemContentStyle(args.column));
     }
     else if (args.value != null)
     {
         var item      = args.item;
         var thumbnail = item.GetThumbnail(item.context ?? args.context);
         GUI.Label(args.rect, Utils.GUIContentTemp(args.value.ToString(), thumbnail), GetItemContentStyle(args.column));
     }
     return(args.value);
 }
コード例 #5
0
        private static object GetObjectPath(SearchColumnEventArgs args)
        {
            var value = args.column.SelectValue(args.item, args.context);

            if (value is UnityEngine.Object obj)
            {
                var objPath = AssetDatabase.GetAssetPath(obj);
                if (!string.IsNullOrEmpty(objPath))
                {
                    return(objPath);
                }
                if (obj is GameObject go)
                {
                    return(SearchUtils.GetTransformPath(go.transform));
                }
            }
            return(value);
        }
コード例 #6
0
        private static object DrawEnabled(SearchColumnEventArgs args)
        {
            if (args.value == null)
            {
                return(null);
            }
            var w = 14f + EditorStyles.toggle.margin.horizontal;

            if (args.column.options.HasAny(SearchColumnFlags.TextAlignmentRight))
            {
                args.rect.xMin = args.rect.xMax - w;
            }
            else if (args.column.options.HasAny(SearchColumnFlags.TextAlignmentCenter))
            {
                args.rect.xMin += (args.rect.width - w) / 2f;
            }
            else
            {
                args.rect.x += EditorStyles.toggle.margin.left;
            }
            args.value = EditorGUI.Toggle(args.rect, (bool)args.value);
            return(args.value);
        }
コード例 #7
0
        private void CellGUI(Rect cellRect, PropertyItem item, int columnIndex, int itemId)
        {
            CenterRectUsingSingleLineHeight(ref cellRect);
            var unclipRect = Utils.Unclip(cellRect);

            if (!unclipRect.Overlaps(m_ViewRect))
            {
                return;
            }

            var column = (SearchColumn)((PropertyColumn)multiColumnHeader.GetColumn(columnIndex)).userDataObj;

            if (column.drawer == null && column.getter == null)
            {
                return;
            }

            // allow to capture tabs
            if (multiColumnHeader.state.visibleColumns.Length > 1)
            {
                if (itemId == state.lastClickedID && HasFocus() && columnIndex == multiColumnHeader.state.visibleColumns[multiColumnHeader.state.visibleColumns[0] == 0 ? 1 : 0])
                {
                    GUI.SetNextControlName(Constants.focusHelper);
                }
            }

            bool isFocused  = false;
            bool isSelected = IsSelected(itemId);
            var  ltd        = item.GetData();
            var  eventArgs  = new SearchColumnEventArgs(ltd, m_TableView.context, column)
            {
                rect     = cellRect,
                focused  = isFocused,
                selected = isSelected
            };

            if (column.getter != null)
            {
                eventArgs.value = column.getter(eventArgs);
            }

            if (eventArgs.value != null && column.drawer == null)
            {
                DefaultDrawing(cellRect, column, eventArgs.value);

                return;
            }

            if (column.drawer == null)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();
            var newValue = column.drawer(eventArgs);

            if (EditorGUI.EndChangeCheck() && column.setter != null)
            {
                eventArgs.value = newValue;
                column.setter?.Invoke(eventArgs);

                var selIds = GetSelection();
                if (selIds.Contains(ltd.id.GetHashCode()))
                {
                    IList <TreeViewItem> rows = FindRows(selIds);

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

                        var data = ((PropertyItem)r).GetData();
                        column.setter?.Invoke(new SearchColumnEventArgs(data, m_TableView.context, column)
                        {
                            value = newValue, multiple = true
                        });
                    }
                }
            }
        }
コード例 #8
0
 static object DrawObjectReference(SearchColumnEventArgs args)
 {
     return(DrawObjectReference(args.rect, args.value));
 }
コード例 #9
0
 public SearchColumnCompareArgs(SearchColumnEventArgs lhs, SearchColumnEventArgs rhs, bool sortAscending)
 {
     this.lhs           = lhs;
     this.rhs           = rhs;
     this.sortAscending = sortAscending;
 }
コード例 #10
0
 private object DefaultSelect(SearchColumnEventArgs args)
 {
     return(args.column.SelectValue(args.item, args.context));
 }