Exemplo n.º 1
0
        private void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Update", EditorStyles.toolbarButton))
            {
                Creator.Build();
                EditorGUIUtility.ExitGUI();
            }

            EditorGUI.BeginChangeCheck();
            var types   = items.Select(item => item.type).ToArray();
            var display = types.Select(t => t.Name).ToArray();

            for (var i = 0; i < display.Length; i++)
            {
                switch (display[i])
                {
                case "Object":
                    display[i] = "Scene";
                    break;

                case "GameObject":
                    display[i] = "Prefab";
                    break;
                }
            }
            ArrayUtility.Insert(ref display, 0, "All");
            var selected = EditorGUILayout.Popup(selectedFilter, display, EditorStyles.toolbarPopup);

            if (EditorGUI.EndChangeCheck())
            {
                selectedFilter = selected;
            }
            EditorGUILayout.EndHorizontal();

            if (items.Count == 0)
            {
                return;
            }

            pos = EditorGUILayout.BeginScrollView(pos);

            var groupBy = items.GroupBy(item => item.searchedGUIContent.tooltip);

            foreach (var group in groupBy)
            {
                var enumerator = @group.GetEnumerator();
                var item       = new Item();
                while (enumerator.MoveNext())
                {
                    item.type = enumerator.Current.type;
                    item.searchedGUIContent = enumerator.Current.searchedGUIContent;
                    item.referenceGUIContents.AddRange(enumerator.Current.referenceGUIContents);
                    item.referencedGUIContents.AddRange(enumerator.Current.referencedGUIContents);
                }

                if (selectedFilter != 0 && item.type != types[selectedFilter - 1])
                {
                    continue;
                }

                EditorGUILayout.BeginHorizontal("box", GUILayout.Width(Screen.width * 0.96f));
                DrawGUIContents(item.searchedGUIContent, item.referenceGUIContents);
                var iconSize = EditorGUIUtility.GetIconSize();
                EditorGUIUtility.SetIconSize(Vector2.one * 32);
                GUILayout.Label(item.searchedGUIContent, GUILayout.Width(Screen.width * 0.3f), GUILayout.ExpandWidth(false));
                EditorGUIUtility.SetIconSize(iconSize);
                PingObjectIfOnMouseDown(item.searchedGUIContent.tooltip);

                DrawGUIContents(item.searchedGUIContent, item.referencedGUIContents);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndScrollView();
        }