UnityEditor.Selection.GetFiltered C# (CSharp) Method

GetFiltered() public static method

Returns the current selection filtered by type and mode.

public static GetFiltered ( Type type, SelectionMode mode ) : Object[]
type System.Type Only objects of this type will be retrieved.
mode SelectionMode Further options to refine the selection.
return Object[]
        public static Object[] GetFiltered(Type type, SelectionMode mode)
        {
            ArrayList list = new ArrayList();
            if ((type == typeof(Component)) || type.IsSubclassOf(typeof(Component)))
            {
                Transform[] transforms = GetTransforms(mode);
                foreach (Transform transform in transforms)
                {
                    Component component = transform.GetComponent(type);
                    if (component != null)
                    {
                        list.Add(component);
                    }
                }
            }
            else if ((type == typeof(GameObject)) || type.IsSubclassOf(typeof(GameObject)))
            {
                Transform[] transformArray3 = GetTransforms(mode);
                foreach (Transform transform2 in transformArray3)
                {
                    list.Add(transform2.gameObject);
                }
            }
            else
            {
                Object[] objectsMode = GetObjectsMode(mode);
                foreach (Object obj2 in objectsMode)
                {
                    if ((obj2 != null) && ((obj2.GetType() == type) || obj2.GetType().IsSubclassOf(type)))
                    {
                        list.Add(obj2);
                    }
                }
            }
            return (Object[]) list.ToArray(typeof(Object));
        }

Usage Example

Exemplo n.º 1
0
        public void DoLocalSelectionChange()
        {
            if (this.m_NextSelectionMine)
            {
                this.m_NextSelectionMine = false;
                return;
            }
            UnityEngine.Object[] filtered = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets);
            string[]             array    = new string[0];
            switch (this.m_FileViewWin.SelType)
            {
            case ASHistoryFileView.SelectionType.All:
                if (Selection.objects.Length != 0)
                {
                    Selection.objects        = new UnityEngine.Object[0];
                    this.m_NextSelectionMine = true;
                }
                this.m_SelectedPath = string.Empty;
                this.m_SelectedGUID = string.Empty;
                this.ClearLV();
                break;

            case ASHistoryFileView.SelectionType.Items:
                if (filtered.Length < 1)
                {
                    this.m_SelectedPath = string.Empty;
                    this.m_SelectedGUID = string.Empty;
                    this.ClearLV();
                    return;
                }
                this.m_SelectedPath = AssetDatabase.GetAssetPath(filtered[0]);
                this.m_SelectedGUID = AssetDatabase.AssetPathToGUID(this.m_SelectedPath);
                array = this.m_FileViewWin.GetImplicitProjectViewSelection();
                break;

            case ASHistoryFileView.SelectionType.DeletedItemsRoot:
                if (Selection.objects.Length != 0)
                {
                    Selection.objects        = new UnityEngine.Object[0];
                    this.m_NextSelectionMine = true;
                }
                array = this.m_FileViewWin.GetAllDeletedItemGUIDs();
                if (array.Length == 0)
                {
                    this.ClearLV();
                    return;
                }
                break;

            case ASHistoryFileView.SelectionType.DeletedItems:
                if (Selection.objects.Length != 0)
                {
                    Selection.objects        = new UnityEngine.Object[0];
                    this.m_NextSelectionMine = true;
                }
                array = this.m_FileViewWin.GetSelectedDeletedItemGUIDs();
                break;
            }
            this.m_Changesets = AssetServer.GetHistorySelected(array);
            if (this.m_Changesets != null)
            {
                this.FilterItems(true);
            }
            else
            {
                this.ClearLV();
            }
            if (array != null && this.m_GUIItems != null && array.Length == 1)
            {
                this.MarkBoldItemsByGUID(this.m_SelectedGUID);
            }
            this.m_ParentWindow.Repaint();
        }
All Usage Examples Of UnityEditor.Selection::GetFiltered