コード例 #1
0
        public static void ClearMakeAllResourcesMerge()
        {
            if (!EditorUtility.DisplayDialog("是否要清理规则文件(全部的或者指定目录的)?", "清理后无法恢复!", "确认清理", "取消操作"))
            {
                Debug.Log(KSwordKitName + ": 资源管理/清理规则文件(全部的或者指定目录的) -> 已取消!");
                return;
            }

            EditorUtility.DisplayProgressBar("清理规则文件(全部的或者指定目录的)", "程序执行中...", 0);
            bool isError = false;

            var watch = Watch.Do(() => {
                try
                {
                    var objects = Selection.objects;
                    // 没有选中任何资源
                    if (objects.Length == 0)
                    {
                        eachFile(Application.dataPath, (dir) => {
                            EditorUtility.DisplayProgressBar("清理规则文件(全部的或者指定目录的)", "正在处理:" + dir.Name, Random.Range(0f, 1f));

                            var rule = System.IO.Path.Combine(dir.FullName, AssetBundleGeneratesRuleFileName);
                            if (System.IO.File.Exists(rule))
                            {
                                FileUtil.DeleteFileOrDirectory(rule);
                            }
                            var rulemeta = rule + ".meta";
                            if (System.IO.File.Exists(rulemeta))
                            {
                                FileUtil.DeleteFileOrDirectory(rulemeta);
                            }
                        });
                    }
                    else
                    {
                        float i = 0;
                        foreach (var _object in objects)
                        {
                            i++;
                            var path = AssetDatabase.GetAssetPath(_object);

                            EditorUtility.DisplayProgressBar("清理规则文件(全部的或者指定目录的)", "正在处理:" + path, i / objects.Length);

                            if (System.IO.File.Exists(path))
                            {
                                if (System.IO.Path.GetFileName(path) == AssetBundleGeneratesRuleFileName)
                                {
                                    FileUtil.DeleteFileOrDirectory(path);
                                }
                                var rulemeta = path + ".meta";
                                if (System.IO.File.Exists(rulemeta))
                                {
                                    FileUtil.DeleteFileOrDirectory(rulemeta);
                                }
                            }
                            else if (System.IO.Directory.Exists(path))
                            {
                                eachFile(path, (dirinfo) => {
                                    EditorUtility.DisplayProgressBar("清理规则文件(全部的或者指定目录的)", "正在处理:" + dirinfo.Name, Random.Range(0f, 1f));
                                    var rule = System.IO.Path.Combine(dirinfo.FullName, AssetBundleGeneratesRuleFileName);
                                    if (System.IO.File.Exists(rule))
                                    {
                                        FileUtil.DeleteFileOrDirectory(rule);
                                    }
                                    var rulemeta = rule + ".meta";
                                    if (System.IO.File.Exists(rulemeta))
                                    {
                                        FileUtil.DeleteFileOrDirectory(rulemeta);
                                    }
                                });
                            }
                        }
                    }

                    AssetDatabase.Refresh();
                }
                catch (System.Exception e)
                {
                    isError = true;
                    Debug.LogError(KSwordKitName + ": 执行 `清理规则文件(全部的或者指定目录的)` 时,发生错误 -> " + e.Message);
                }
            });

            EditorUtility.ClearProgressBar();
            if (!isError)
            {
                UnityEngine.Debug.Log(KSwordKitName + ": 资源管理/清理规则文件(全部的或者指定目录的) -> 完成! (" + watch.Elapsed.TotalSeconds + "s)");
            }
        }
コード例 #2
0
        public static void SetMakeAllResourcesMerge()
        {
            var objects = Selection.objects;

            // 没有选中任何资源
            if (objects.Length == 0)
            {
                UnityEngine.Debug.LogWarning(KSwordKitName + ": 未选中任何资源,无法创建规则文件!");
                return;
            }

            EditorUtility.DisplayProgressBar("创建规则文件(须选中某位置)", "程序执行中...", 0);
            bool isError = false;
            var  watch   = Watch.Do(() => {
                try
                {
                    var rulefilepath = AssetBundleGeneratesRuleFileName;
                    float i          = 0;
                    foreach (var _object in objects)
                    {
                        i++;
                        var path = AssetDatabase.GetAssetPath(_object);

                        EditorUtility.DisplayProgressBar("创建规则文件(须选中某位置)", "正在处理:" + path, i / objects.Length);

                        if (System.IO.File.Exists(path))
                        {
                            var fileinfo = new System.IO.FileInfo(path);
                            rulefilepath = System.IO.Path.Combine(fileinfo.Directory.FullName, AssetBundleGeneratesRuleFileName);
                        }
                        else if (System.IO.Directory.Exists(path))
                        {
                            rulefilepath = System.IO.Path.Combine(path, AssetBundleGeneratesRuleFileName);
                        }

                        if (!System.IO.File.Exists(rulefilepath))
                        {
                            var file = System.IO.File.CreateText(rulefilepath);
                            file.Write(AssetBundleGeneratesRuleFileContent);
                            file.Close();
                        }
                        else
                        {
                            UnityEngine.Debug.LogWarning(KSwordKitName + ": 该目录下已存在规则文件,无需再次创建!RuleFilePath: " + rulefilepath);
                        }
                    }

                    AssetDatabase.Refresh();
                }
                catch (System.Exception e)
                {
                    isError = true;
                    Debug.LogError(KSwordKitName + ": 执行 `资源管理/创建规则文件(须选中某位置)` 时,发生错误 -> " + e.Message);
                }
            });

            EditorUtility.ClearProgressBar();
            if (!isError)
            {
                UnityEngine.Debug.Log(KSwordKitName + ": 资源管理/创建规则文件(须选中某位置) -> 完成! (" + watch.Elapsed.TotalSeconds + "s)");
            }
        }
コード例 #3
0
        public static void SetAssetLabels()
        {
            var objects = Selection.objects;

            // 没有选中任何资源
            if (objects.Length == 0)
            {
                UnityEngine.Debug.LogWarning(KSwordKitName + ": 未选中任何资源,无法自动设置标签!");
                return;
            }

            EditorUtility.DisplayProgressBar("自动设置资源标签(须选中某些资源)", "程序执行中...", 0);
            bool isError = false;

            var watch = Watch.Do(() =>
            {
                try
                {
                    // 选中的所有文件
                    var selectedFileList = new List <string>();
                    foreach (var o in objects)
                    {
                        var path = AssetDatabase.GetAssetPath(o);
                        EditorUtility.DisplayProgressBar("自动设置资源标签(须选中某些资源)", "正在处理:" + path, Random.Range(0f, 1f));

                        if (System.IO.File.Exists(path))
                        {
                            var fileinfo = new System.IO.FileInfo(path);
                            selectedFileList.Add(fileinfo.FullName);
                            setABNameByFile(ConvertAssetPathToAssetBundleName(fileinfo.FullName), fileinfo.FullName);
                        }
                    }

                    objects = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
                    foreach (var o in objects)
                    {
                        var path = AssetDatabase.GetAssetPath(o);
                        EditorUtility.DisplayProgressBar("自动设置资源标签(须选中某些资源)", "正在处理:" + path, Random.Range(0f, 1f));

                        if (System.IO.File.Exists(path))
                        {
                            var fileinfo = new System.IO.FileInfo(path);
                            if (selectedFileList.Contains(fileinfo.FullName))
                            {
                                continue;
                            }

                            var dir    = fileinfo.Directory;
                            var abname = ConvertAssetPathToAssetBundleName(dir.FullName);
                            if (!System.IO.File.Exists(System.IO.Path.Combine(dir.FullName, AssetBundleRuleEditor.AssetBundleGeneratesRuleFileName)))
                            {
                                var dirpath  = dir.FullName;
                                var datapath = new System.IO.DirectoryInfo(Application.dataPath).FullName;
                                dirpath      = dirpath.Substring(datapath.Length + 1);
                                dirpath      = dirpath.Replace('\\', '/');
                                var dirs     = dirpath.Split('/');
                                var dirname  = string.Empty;
                                foreach (var _dir in dirs)
                                {
                                    if (string.IsNullOrEmpty(dirname))
                                    {
                                        dirname = _dir;
                                    }
                                    else
                                    {
                                        dirname = System.IO.Path.Combine(dirname, _dir);
                                    }

                                    var _path = System.IO.Path.Combine(Application.dataPath, dirname);
                                    //Debug.Log("文件: " + path + ", 上层目录:" + _path);
                                    if (System.IO.File.Exists(System.IO.Path.Combine(_path, AssetBundleRuleEditor.AssetBundleGeneratesRuleFileName)))
                                    {
                                        abname = ConvertAssetPathToAssetBundleName(new System.IO.DirectoryInfo(_path).FullName);
                                        //Debug.Log("rule 文件存在:" + _path +", 标签:"+ abname);
                                        break;
                                    }
                                }
                            }

                            setABNameByFile(abname, fileinfo.FullName);
                        }
                    }

                    AssetDatabase.Refresh();
                }
                catch (System.Exception e)
                {
                    isError = true;
                    Debug.LogError(KSwordKitName + ": 执行 `自动设置资源标签(须选中某些资源)` 时,发生错误 -> " + e.Message);
                }
            });

            EditorUtility.ClearProgressBar();
            if (!isError)
            {
                UnityEngine.Debug.Log(KSwordKitName + ": 资源管理/自动设置资源标签(须选中某些资源) -> 完成! (" + watch.Elapsed.TotalSeconds + "s)");
            }
        }