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 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();
        }
 private string GetFirstSelected()
 {
     UnityEngine.Object[] filtered = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets);
     return((filtered.Length == 0) ? string.Empty : AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(filtered[0])));
 }
Example #3
0
        private void DrawTiaoZhen()                              // 调整UI
        {
            Transform[] curSelect = Selection.GetTransforms(SelectionMode.TopLevel);
            int         length    = curSelect.Length;

            #region  择一个 GameObject 控制其上下位置

            MyCreate.Box(() =>
            {
                MyCreate.Text("功能:".AddYellow() + " 选择一个 GameObject 控制其上下位置".AddGreen());
                m_Tools.Text_H("  点击 1 个");
                GUI.enabled = length == 1;
                FourButton("  上一格 ↑", "  下一格 ↓", "  最里层 ↑↑↑", "  最外层 ↓↓↓", () =>
                {
                    //上一格
                    int curIndex = curSelect[0].GetSiblingIndex();
                    if (curIndex > 0)
                    {
                        curSelect[0].SetSiblingIndex(curIndex - 1);
                    }
                }, () =>
                {
                    // 下一格
                    int curIndex  = curSelect[0].GetSiblingIndex();
                    int child_num = curSelect[0].parent.childCount;
                    if (curIndex < child_num - 1)
                    {
                        curSelect[0].SetSiblingIndex(curIndex + 1);
                    }
                }, () =>
                {
                    //最里层
                    curSelect[0].SetAsFirstSibling();
                }, () =>
                {
                    //最外层
                    curSelect[0].SetAsLastSibling();
                });
                GUI.enabled = true;
            });

            #endregion

            #region 水平/垂直 均匀排布

            MyCreate.Box(() =>
            {
                MyCreate.Text("功能:".AddYellow() + " 水平/垂直 均匀排布".AddGreen());
                m_Tools.Text_H("  需要点击 3 个或以上");
                GUI.enabled = length > 2;
                ThreeButton("    水平均匀  |||", "    垂直均匀  ☰", "    水平 + 垂直", () =>
                {
                    // 水平均匀 |||
                    ShuiPin(length);
                }, () =>
                {
                    // 垂直均匀  ☰
                    ShuZhi(length);
                }, () =>
                {
                    // 水平 + 垂直
                    ShuiPin(length);
                    ShuZhi(length);
                });
                GUI.enabled = true;
            });

            #endregion

            #region 设置一样大小

            MyCreate.Box(() =>
            {
                GUI.enabled = length > 1;
                MyCreate.Text("功能:".AddYellow() + " 设置一样大小".AddGreen());
                m_Tools.Text_H("  需要点击 2 个或以上,一样大按最大的来算");
                GUI.enabled = length > 1;
                m_Tools.TwoButton("一样大 ■", "一样小 ▪", () =>
                {
                    float height = Mathf.Max(Selection.gameObjects.Select(obj => ((RectTransform)obj.transform).sizeDelta.y).ToArray());
                    float width  = Mathf.Max(Selection.gameObjects.Select(obj => ((RectTransform)obj.transform).sizeDelta.x).ToArray());
                    foreach (GameObject gameObject in Selection.gameObjects)
                    {
                        ((RectTransform)gameObject.transform).sizeDelta = new Vector2(width, height);
                    }
                }, () =>
                {
                    float height = Mathf.Min(Selection.gameObjects.Select(obj => ((RectTransform)obj.transform).sizeDelta.y).ToArray());
                    float width  = Mathf.Min(Selection.gameObjects.Select(obj => ((RectTransform)obj.transform).sizeDelta.x).ToArray());
                    foreach (GameObject gameObject in Selection.gameObjects)
                    {
                        ((RectTransform)gameObject.transform).sizeDelta = new Vector2(width, height);
                    }
                });
                GUI.enabled = true;
            });


            #endregion

            #region 设置一样字体大小

            MyCreate.Box(() =>
            {
                MyCreate.Text("功能:".AddYellow() + " 设置一样字体大小".AddGreen());
                m_Tools.Text_H("  需要点击 2 个或以上的 Text");

                Text[] texts = Selection.GetFiltered <Text>(SelectionMode.TopLevel);
                GUI.enabled  = texts.Length > 1;
                m_Tools.TwoButton("一样大字号", "一样小字号", () =>
                {
                    int maxSiz = 0;
                    foreach (Text text in texts)
                    {
                        if (text.fontSize < maxSiz)
                        {
                            text.fontSize = maxSiz;
                        }
                        else
                        {
                            maxSiz = text.fontSize;
                        }
                    }
                }, () =>
                {
                    int minSiz = 100;
                    foreach (Text text in texts)
                    {
                        if (text.fontSize > minSiz)
                        {
                            text.fontSize = minSiz;
                        }
                        else
                        {
                            minSiz = text.fontSize;
                        }
                    }
                });
                GUI.enabled = true;
            });
            #endregion
        }