コード例 #1
0
    private void Awake()
    {
        _lastTime = EditorApplication.timeSinceStartup;

        // 加载提示图片
        string folderPath = EditorTools.FindFolder(Application.dataPath, "ParticleProfiler");

        if (string.IsNullOrEmpty(folderPath) == false)
        {
            string temp = EditorTools.AbsolutePathToAssetPath(folderPath);
            _texTips = AssetDatabase.LoadAssetAtPath <Texture2D>($"{temp}/GUI/tips.png");
            if (_texTips == null)
            {
                Debug.LogWarning("Not found ParticleProfilerWindows tips texture.");
            }
        }
        else
        {
            Debug.LogWarning("Not found ParticleProfiler folder.");
        }

        // 加载测试场景
        string path = EditorPrefs.GetString(PROFILER_SCENE_KEY, string.Empty);

        if (string.IsNullOrEmpty(path) == false)
        {
            _profilerScene = AssetDatabase.LoadAssetAtPath <SceneAsset>(path);
        }
    }
コード例 #2
0
    private void OnGUI()
    {
        // 列表显示
        EditorGUILayout.Space();
        EditorGUILayout.LabelField($"Pack Path List");
        for (int i = 0; i < BuildSettingData.Setting.Elements.Count; i++)
        {
            string folderPath = BuildSettingData.Setting.Elements[i].FolderPath;
            BuildSetting.EFolderPackRule packRule = BuildSettingData.Setting.Elements[i].PackRule;
            BuildSetting.EBundleNameRule nameRule = BuildSettingData.Setting.Elements[i].NameRule;

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(folderPath);

                BuildSetting.EFolderPackRule newPackRule = (BuildSetting.EFolderPackRule)EditorGUILayout.EnumPopup(packRule, GUILayout.MaxWidth(150));
                if (newPackRule != packRule)
                {
                    packRule = newPackRule;
                    BuildSettingData.ModifyElement(folderPath, packRule, nameRule);
                }

                BuildSetting.EBundleNameRule newNameRule = (BuildSetting.EBundleNameRule)EditorGUILayout.EnumPopup(nameRule, GUILayout.MaxWidth(150));
                if (newNameRule != nameRule)
                {
                    nameRule = newNameRule;
                    BuildSettingData.ModifyElement(folderPath, packRule, nameRule);
                }

                if (GUILayout.Button("-", GUILayout.MaxWidth(40)))
                {
                    BuildSettingData.RemoveElement(folderPath);
                    break;
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        // 添加按钮
        if (GUILayout.Button("+"))
        {
            string resultPath = EditorTools.OpenFolderPanel("+", _lastOpenFolderPath);
            if (resultPath != null)
            {
                _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath);
                BuildSettingData.AddElement(_lastOpenFolderPath);
            }
        }
    }
コード例 #3
0
    private void OnGUI()
    {
        if (AssetImporterProcessor.Setting == null)
        {
            AssetImporterProcessor.LoadSettingFile();
        }

        if (_isInit == false)
        {
            _isInit = true;
            Init();
        }

        // 添加按钮
        if (GUILayout.Button("+"))
        {
            string resultPath = EditorTools.OpenFolderPanel("+", _lastOpenFolderPath);
            if (resultPath != null)
            {
                _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath);
                AssetImporterProcessor.AddSettingElement(_lastOpenFolderPath);
            }
        }

        // 列表显示
        for (int i = 0; i < AssetImporterProcessor.Setting.Elements.Count; i++)
        {
            string folderPath    = AssetImporterProcessor.Setting.Elements[i].FolderPath;
            string processorName = AssetImporterProcessor.Setting.Elements[i].ProcessorName;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(folderPath);

            int index    = NameToIndex(processorName);
            int newIndex = EditorGUILayout.Popup(index, _processorClassArray, GUILayout.MaxWidth(150));
            if (newIndex != index)
            {
                string processClassName = IndexToName(newIndex);
                AssetImporterProcessor.ModifySettingElement(folderPath, processClassName);
            }

            if (GUILayout.Button("-", GUILayout.MaxWidth(80)))
            {
                AssetImporterProcessor.RemoveSettingElement(folderPath);
                break;
            }
            EditorGUILayout.EndHorizontal();
        }
    }
コード例 #4
0
    /// <summary>
    /// 检测预制件是否损坏
    /// </summary>
    private void CheckAllPrefabValid()
    {
        // 获取打包目录下所有文件
        string        packPath = _assetBuilder.PackPath;
        DirectoryInfo dirInfo  = new DirectoryInfo(packPath);

        FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);

        // 进度条相关
        int checkCount   = 0;
        int invalidCount = 0;

        EditorUtility.DisplayProgressBar("进度", $"检测预制件文件是否损坏:{checkCount}/{files.Length}", (float)checkCount / files.Length);

        // 获取所有资源列表
        foreach (FileInfo fileInfo in files)
        {
            string assetPath = EditorTools.AbsolutePathToAssetPath(fileInfo.FullName);
            string ext       = System.IO.Path.GetExtension(assetPath);
            if (ext == ".prefab")
            {
                UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
                if (prefab == null)
                {
                    invalidCount++;
                    Debug.LogError($"[Build] 发现损坏预制件:{assetPath}");
                }
            }

            // 进度条相关
            checkCount++;
            EditorUtility.DisplayProgressBar("进度", $"检测预制件文件是否损坏:{checkCount}/{files.Length}", (float)checkCount / files.Length);
        }

        EditorUtility.ClearProgressBar();
        if (invalidCount == 0)
        {
            UnityEngine.Debug.Log($"没有发现损坏预制件");
        }
    }
コード例 #5
0
    private void OnDrawGUITools()
    {
        GUILayout.Space(50);
        using (new EditorGUI.DisabledScope(false))
        {
            _showToolsFoldout = EditorGUILayout.Foldout(_showToolsFoldout, "工具");
            if (_showToolsFoldout)
            {
                EditorGUILayout.Space();

                if (GUILayout.Button("检测损坏预制件", GUILayout.MaxWidth(120), GUILayout.MaxHeight(40)))
                {
                    EditorApplication.delayCall += CheckAllPrefabValid;
                }

                if (GUILayout.Button("设置打包路径", GUILayout.MaxWidth(120), GUILayout.MaxHeight(40)))
                {
                    string resultPath = EditorTools.OpenFolderPanel("Open Folder Dialog", _assetBuilder.PackPath);
                    if (resultPath != null)
                    {
                        string newPackPath = EditorTools.AbsolutePathToAssetPath(resultPath);
                        _assetBuilder.PackPath = newPackPath;
                        EditorPrefs.SetString(StrEditorPackingPath, _assetBuilder.PackPath);
                    }
                }

                if (GUILayout.Button("刷新流目录(清空后拷贝所有补丁包到流目录)", GUILayout.MaxWidth(300), GUILayout.MaxHeight(40)))
                {
                    EditorApplication.delayCall += RefreshStreammingFolder;
                }

                if (GUILayout.Button("刷新输出主目录(清空后拷贝所有补丁包到输出主目录)", GUILayout.MaxWidth(300), GUILayout.MaxHeight(40)))
                {
                    EditorApplication.delayCall += RefreshOutputMainFolder;
                }
            }
        }
    }
コード例 #6
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();
    }
コード例 #7
0
    /// <summary>
    /// 准备工作
    /// </summary>
    private List <AssetInfo> PrepareWork()
    {
        int progressBarCount = 0;
        Dictionary <string, AssetInfo> allAsset = new Dictionary <string, AssetInfo>();

        // 获取打包目录下所有文件
        DirectoryInfo dirInfo = new DirectoryInfo(PackPath);

        FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);

        // 获取所有资源列表
        foreach (FileInfo fileInfo in files)
        {
            string assetPath = EditorTools.AbsolutePathToAssetPath(fileInfo.FullName);
            if (ValidateAsset(assetPath))
            {
                List <AssetInfo> depends = GetDependencies(assetPath);
                for (int i = 0; i < depends.Count; i++)
                {
                    AssetInfo assetInfo = depends[i];
                    if (allAsset.ContainsKey(assetInfo.AssetPath))
                    {
                        AssetInfo cacheInfo = allAsset[assetInfo.AssetPath];
                        cacheInfo.DependCount++;
                    }
                    else
                    {
                        allAsset.Add(assetInfo.AssetPath, assetInfo);
                    }
                }
            }
            // 进度条
            progressBarCount++;
            EditorUtility.DisplayProgressBar("进度", $"依赖文件分析:{progressBarCount}/{files.Length}", (float)progressBarCount / files.Length);
        }
        EditorUtility.ClearProgressBar();
        progressBarCount = 0;

        // 移除零依赖的资源
        List <string> removeList = new List <string>();

        foreach (KeyValuePair <string, AssetInfo> pair in allAsset)
        {
            if (pair.Value.IsPackAsset)
            {
                continue;
            }
            if (pair.Value.IsAtalsSpriteAsset)
            {
                continue;
            }
            if (pair.Value.DependCount == 0)
            {
                removeList.Add(pair.Value.AssetPath);
            }
        }
        for (int i = 0; i < removeList.Count; i++)
        {
            allAsset.Remove(removeList[i]);
        }

        // 设置资源的打包标签
        foreach (KeyValuePair <string, AssetInfo> pair in allAsset)
        {
            SetAssetPackingTag(pair.Value);
            // 进度条
            progressBarCount++;
            EditorUtility.DisplayProgressBar("进度", $"设置打包标签:{progressBarCount}/{allAsset.Count}", (float)progressBarCount / allAsset.Count);
        }
        EditorUtility.ClearProgressBar();
        progressBarCount = 0;

        // 构建资源列表
        List <AssetInfo> result = new List <AssetInfo>();

        foreach (KeyValuePair <string, AssetInfo> pair in allAsset)
        {
            result.Add(pair.Value);
        }

        return(result);
    }