コード例 #1
0
        private void DrawResults()
        {
            if (_results == null || _results.Count == 0)
            {
                return;
            }

            _scrollPos = GUILayout.BeginScrollView(_scrollPos);

            // 显示依赖列表
            foreach (var valuePair in _results)
            {
                // 绘制头部
                string HeaderName = valuePair.Key;
                if (EditorTools.DrawHeader(HeaderName))
                {
                    // 绘制报告列表
                    foreach (var report in valuePair.Value)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField($"名称: {report.AssetObject.name} 报告: {report.ReportInfo}");
                        if (report.AssetObject.GetType() == typeof(UnityEngine.Texture) || report.AssetObject.GetType() == typeof(UnityEngine.Texture2D))
                        {
                            EditorGUILayout.ObjectField("", report.AssetObject, typeof(UnityEngine.Texture), false, GUILayout.Width(80));
                        }
                        else
                        {
                            EditorGUILayout.ObjectField("", report.AssetObject, typeof(UnityEngine.Object), false, GUILayout.Width(80));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            GUILayout.EndScrollView();
        }
コード例 #2
0
        private void OnGUI()
        {
            // 搜索路径
            EditorGUILayout.Space();
            if (GUILayout.Button("设置搜索目录", GUILayout.MaxWidth(80)))
            {
                string resultPath = EditorTools.OpenFolderPanel("搜索目录", _searchFolderPath);
                if (resultPath != null)
                {
                    _searchFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath);
                }
            }
            EditorGUILayout.LabelField($"搜索目录:{_searchFolderPath}");

            // 搜索类型
            _serachType = (EAssetSearchType)EditorGUILayout.EnumPopup("搜索类型", _serachType);

            // 搜索目标
            _searchObject = EditorGUILayout.ObjectField($"搜索目标", _searchObject, typeof(UnityEngine.Object), false);
            if (_searchObject != null && _searchObject.GetType() == typeof(Texture2D))
            {
                string assetPath    = AssetDatabase.GetAssetPath(_searchObject.GetInstanceID());
                var    spriteObject = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
                if (spriteObject != null)
                {
                    _searchObject = spriteObject;
                }
            }

            // 执行搜索
            EditorGUILayout.Space();
            if (GUILayout.Button("搜索"))
            {
                if (_searchObject == null)
                {
                    EditorUtility.DisplayDialog("错误", "请先设置搜索目标", "确定");
                    return;
                }
                string assetPath = AssetDatabase.GetAssetPath(_searchObject.GetInstanceID());
                FindReferenceInProject(assetPath, _searchFolderPath, _serachType);
            }
            EditorGUILayout.Space();

            // 如果字典类为空
            if (_collection == null)
            {
                return;
            }

            // 如果收集列表为空
            if (CheckCollectIsEmpty())
            {
                EditorGUILayout.LabelField("提示:没有找到任何被依赖资源。");
                return;
            }

            _scrollPos = GUILayout.BeginScrollView(_scrollPos);

            // 显示依赖列表
            foreach (EAssetFileExtension value in Enum.GetValues(typeof(EAssetFileExtension)))
            {
                List <string> collect = _collection[value];
                if (collect.Count == 0)
                {
                    continue;
                }

                string HeaderName = value.ToString();
                if (value == EAssetFileExtension.prefab)
                {
                    HeaderName = "预制体";
                }
                else if (value == EAssetFileExtension.fbx)
                {
                    HeaderName = "模型";
                }
                else if (value == EAssetFileExtension.cs)
                {
                    HeaderName = "脚本";
                }
                else if (value == EAssetFileExtension.png || value == EAssetFileExtension.jpg)
                {
                    HeaderName = "图片";
                }
                else if (value == EAssetFileExtension.mat)
                {
                    HeaderName = "材质球";
                }
                else if (value == EAssetFileExtension.shader)
                {
                    HeaderName = "着色器";
                }
                else if (value == EAssetFileExtension.ttf)
                {
                    HeaderName = "字体";
                }
                else if (value == EAssetFileExtension.anim)
                {
                    HeaderName = "动画";
                }
                else if (value == EAssetFileExtension.unity)
                {
                    HeaderName = "场景";
                }
                else
                {
                    throw new NotImplementedException(value.ToString());
                }

                // 绘制头部
                if (EditorTools.DrawHeader(HeaderName))
                {
                    // 绘制预制体专属按钮
                    if (value == EAssetFileExtension.prefab)
                    {
                        if (GUILayout.Button("过滤", GUILayout.MaxWidth(80)))
                        {
                            FilterReference();
                        }
                        if (GUILayout.Button("FindAll", GUILayout.MaxWidth(80)))
                        {
                            FindAll(collect);
                        }
                    }

                    // 绘制依赖列表
                    foreach (string item in collect)
                    {
                        EditorGUILayout.BeginHorizontal();
                        UnityEngine.Object go = AssetDatabase.LoadAssetAtPath(item, typeof(UnityEngine.Object));
                        if (value == EAssetFileExtension.unity)
                        {
                            EditorGUILayout.ObjectField(go, typeof(SceneView), true);
                        }
                        else
                        {
                            EditorGUILayout.ObjectField(go, typeof(UnityEngine.Object), false);
                        }

                        // 绘制预制体专属按钮
                        if (value == EAssetFileExtension.prefab)
                        {
                            if (GUILayout.Button("Find", GUILayout.MaxWidth(80)))
                            {
                                FindOne(go as GameObject);
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            GUILayout.EndScrollView();
        }