Ejemplo n.º 1
0
        public static void GenResBuildByDir(string dir, string pattern)
        {
            string relative2 = sResDir;

            if (!string.IsNullOrEmpty(dir) && Directory.Exists(dir))
            {
                //查看该文件夹下是否有文件,有文件将该文件夹作为一个bundle
                string[] files = Directory.GetFiles(dir, pattern, SearchOption.TopDirectoryOnly);
                int      count = 0;
                foreach (var f in files)
                {
                    if (BuilderConfig.IsResFile(f))
                    {
                        count += AsbNameSetting.GetHasAsbName(f) ? 0 : 1;
                        break;
                    }
                }
                if (count > 0)
                {
                    files = Directory.GetFiles(dir, pattern, SearchOption.AllDirectories);
                    string asbName = Tools.GetAsbName(Tools.RelativeTo(dir, relative2));
                    // List<string> list = new List<string>();
                    for (int i = 0; i < files.Length; i++)
                    {
                        string f = files[i];
                        if (BuilderConfig.IsResFile(f))
                        {
                            string resPath = Tools.RelativeTo(f, Application.dataPath, true);
                            AsbNameSetting.SetBundleName(resPath, asbName, true);
                        }
                    }
                }
                else
                {
                    //如果文件夹下没有文件,遍历其子文件夹
                    string[] dirs = Directory.GetDirectories(dir);
                    if (dirs.Length > 0)
                    {
                        foreach (var d in dirs)
                        {
                            GenResBuildByDir(d, pattern);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///设置资源的AssetBundle Name
        /// </summary>
        /// <param name="resPath">以Assets/开头的相对文件路径</param>
        /// <param name="bundleName">AssetBundle Name.</param>
        /// <param name="skipIfHas">If set to <c>true</c> 跳过已经设置AssetBundle name的</param>
        public static void SetBundleName(string resPath, string bundleName, bool skipIfHas = false)
        {
            if (BuilderConfig.IsResFile(resPath))
            {
                AssetImporter importer = AssetImporter.GetAtPath(resPath);

                if (importer && importer.assetBundleName != bundleName)
                {
                    if (skipIfHas && !string.IsNullOrEmpty(importer.assetBundleName))
                    {
                        //已经有Assetbundle name, 跳过
                        return;
                    }
                    importer.assetBundleName = bundleName;
                    Debug.LogFormat("设置 Assetbundle 名称:{0} -----> {1}", resPath, bundleName);
                }
            }
        }
Ejemplo n.º 3
0
        public static void GenLuaBuildByDir(string dir, string pattern)
        {
            if (!string.IsNullOrEmpty(dir) && Directory.Exists(dir))
            {
                string   relative2 = sTempLuaDir;
                string[] files     = Directory.GetFiles(dir, pattern, SearchOption.TopDirectoryOnly);
                string   asbName   = "lua/" + Tools.GetAsbName(Tools.RelativeTo(dir, relative2, true));

                for (int i = 0; i < files.Length; i++)
                {
                    string f = files[i];
                    if (BuilderConfig.IsResFile(f))
                    {
                        AsbNameSetting.SetBundleName(Tools.RelativeTo(files[i], Application.dataPath, true), asbName, true);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        //[MenuItem("Assets/打包测试")]
        //public static void BuildAll()
        //{
        //    string outDir = Application.dataPath.Replace("Assets", "AssetBundles/test");
        //    Debug.Log("打包路径:" + outDir);
        //    Tools.CheckDirExists(outDir, true);
        //    BuildPipeline.BuildAssetBundles(outDir, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
        //}

        private static void _setBundleNameByPath(string path)
        {
            string fullPath = path;

            //if (!Path.IsPathRooted(path) && !path.StartsWith(Application.dataPath, StringComparison.Ordinal))
            if (!path.StartsWith(Application.dataPath, StringComparison.Ordinal))
            {
                fullPath = Tools.PathCombine(Directory.GetParent(Application.dataPath).ToString(), path);
            }
            else
            {
                path = Tools.RelativeTo(path, Tools.GetResPath(), true);
            }

            if (File.Exists(fullPath))
            {
                if (BuilderConfig.IsResFile(path))
                {
                    string asbName = fullPath.Substring(0, fullPath.Length - Path.GetExtension(fullPath).Length);
                    //asbName = Tools.RelativeTo(asbName, Tools.GetResPath()) + GameConfig.STR_ASB_EXT;
                    asbName = Tools.GetAsbName(Tools.RelativeTo(asbName, Tools.GetResPath()));
                    SetBundleName(path, asbName.ToLower());
                }
            }
            else if (Directory.Exists(fullPath))
            {
                string[] files = Directory.GetFiles(fullPath, "*.*", SearchOption.AllDirectories);
                //string asbName = Tools.RelativeTo(fullPath, Tools.GetResPath()) + GameConfig.STR_ASB_EXT;
                string asbName = Tools.GetAsbName(Tools.RelativeTo(fullPath, Tools.GetResPath()));

                foreach (var f in files)
                {
                    if (BuilderConfig.IsResFile(f))
                    {
                        string assetPath = Tools.RelativeTo(f, Application.dataPath, true);
                        SetBundleName(assetPath, asbName.ToLower());
                    }
                }
            }
        }