Exemple #1
0
        /// <summary>
        // 递归处理文件夹下所有Asset 文件
        /// </summary>
        /// <param name="folderPath">Asset目录下文件夹</param>
        private static void AutoGenAssetNameInFolder(string folderPath, bool useFolderName)
        {
            if (folderPath == null)
            {
                Log.w("Folder Path Is Null!");
                return;
            }

            Log.i("Start Set Asset Name. Folder:" + folderPath);
            string workPath        = EditorUtils.AssetsPath2ABSPath(folderPath);              //EditUtils.GetFullPath4AssetsPath(folderPath);
            string assetBundleName = EditorUtils.AssetPath2ReltivePath(folderPath).ToLower(); //EditUtils.GetReltivePath4AssetPath(folderPath).ToLower();

            assetBundleName = assetBundleName.Replace("resources/", "");
            //处理文件
            var filePaths = Directory.GetFiles(workPath);

            for (int i = 0; i < filePaths.Length; ++i)
            {
                if (!AssetFileFilter.IsAsset(filePaths[i]))
                {
                    continue;
                }

                string fileName = Path.GetFileName(filePaths[i]);

                string fullFileName = string.Format("{0}/{1}", folderPath, fileName);

                AssetImporter ai = AssetImporter.GetAtPath(fullFileName);
                if (ai == null)
                {
                    Log.e("Not Find Asset:" + fullFileName);
                    return;
                }
                else
                {
                    if (useFolderName)
                    {
                        ai.assetBundleName = assetBundleName;
                    }
                    else
                    {
                        ai.assetBundleName = string.Format("{0}/{1}", assetBundleName, PathHelper.FileNameWithoutSuffix(fileName));
                    }
                }

                //ai.SaveAndReimport();
                //Log.i("Success Process Asset:" + fileName);
            }

            //递归处理文件夹
            var dirs = Directory.GetDirectories(workPath);

            for (int i = 0; i < dirs.Length; ++i)
            {
                string fileName = Path.GetFileName(dirs[i]);

                fileName = string.Format("{0}/{1}", folderPath, fileName);
                AutoGenAssetNameInFolder(fileName, useFolderName);
            }
        }
Exemple #2
0
        private static void BuildAssetBundlesInFolder(string folderPath)
        {
            if (folderPath == null)
            {
                Log.w("Folder Path Is Null.");
                return;
            }

            Log.i("Start Build AssetBundle:" + folderPath);
            string fullFolderPath  = EditorUtils.AssetsPath2ABSPath(folderPath);    //EditUtils.GetFullPath4AssetsPath(folderPath);
            string assetBundleName = EditorUtils.AssetPath2ReltivePath(folderPath); // EditUtils.GetReltivePath4AssetPath(folderPath);
            var    filePaths       = Directory.GetFiles(fullFolderPath);

            AssetBundleBuild abb = new AssetBundleBuild();

            abb.assetBundleName = assetBundleName;

            List <string> fileNameList = new List <string>();

            for (int i = 0; i < filePaths.Length; ++i)
            {
                if (!AssetFileFilter.IsAsset(filePaths[i]))
                {
                    continue;
                }

                string fileName = Path.GetFileName(filePaths[i]);
                fileName = string.Format("{0}/{1}", folderPath, fileName);
                fileNameList.Add(fileName);
            }

            if (fileNameList.Count <= 0)
            {
                Log.w("Not Find Asset In Folder:" + folderPath);
                return;
            }

            abb.assetNames = fileNameList.ToArray();
            BuildPipeline.BuildAssetBundles(FrameworkConfigData.EDITOR_AB_EXPORT_ROOT_FOLDER,
                                            new AssetBundleBuild[1] {
                abb
            },
                                            BuildAssetBundleOptions.ChunkBasedCompression,
                                            BuildTarget.StandaloneWindows);
        }
        private static void BuildAssetBundlesInFolder(string folderPath)
        {
            if (folderPath == null)
            {
                Log.W("Folder Path Is Null.");
                return;
            }

            Log.I("Start Build AssetBundle:" + folderPath);
            var fullFolderPath  = EditorUtils.AssetsPath2ABSPath(folderPath);    //EditUtils.GetFullPath4AssetsPath(folderPath);
            var assetBundleName = EditorUtils.AssetPath2ReltivePath(folderPath); // EditUtils.GetReltivePath4AssetPath(folderPath);
            var filePaths       = Directory.GetFiles(fullFolderPath);

            AssetBundleBuild abb = new AssetBundleBuild();

            abb.assetBundleName = assetBundleName;

            List <string> fileNameList = new List <string>();

            foreach (var filePath in filePaths)
            {
                if (!filePath.EndsWith(".meta"))
                {
                    continue;
                }

                var fileName = Path.GetFileName(filePath);
                fileName = string.Format("{0}/{1}", folderPath, fileName);
                fileNameList.Add(fileName);
            }

            if (fileNameList.Count <= 0)
            {
                Log.W("Not Find Asset In Folder:" + folderPath);
                return;
            }

            abb.assetNames = fileNameList.ToArray();
            BuildPipeline.BuildAssetBundles(ResKitUtil.EDITOR_AB_EXPORT_ROOT_FOLDER,
                                            new[] { abb },
                                            BuildAssetBundleOptions.ChunkBasedCompression,
                                            BuildTarget.StandaloneWindows);
        }
Exemple #4
0
        private static void ProcessAssetBundleTag(string path, bool tag)
        {
            //获得 开头为Assets/的资源
            AssetImporter importer = AssetImporter.GetAtPath(path);

            if (importer == null)
            {
                Log.e("#Not Find Asset:" + path);
                return;
            }

            string fullPath = EditorUtils.AssetsPath2ABSPath(path);

            if (IO.IsDirExist(fullPath))
            {
                return;
            }

            if (tag)
            {
                string dirName = Path.GetDirectoryName(path);
                //Debug.LogError(dirName);
                string assetBundleName = EditorUtils.AssetPath2ReltivePath(dirName).ToLower();
                //Debug.LogError(assetBundleName);

                if (path.Contains("FolderMode"))
                {
                    importer.assetBundleName = assetBundleName + EngineDefine.BUNDLE_EXTEND;
                }
                else
                {
                    importer.assetBundleName = string.Format("{0}/{1}{2}", assetBundleName, PathHelper.FileNameWithoutExtend(Path.GetFileName(path)), EngineDefine.BUNDLE_EXTEND);
                }
            }
            else
            {
                importer.assetBundleName = string.Empty;
            }
        }