示例#1
0
        /// <summary>
        /// 活的构建的数据
        /// </summary>
        /// <param name="manifestPath"></param>
        /// <returns></returns>
        private static List <AssetBundleBuild> GenerateAssetBundleBuildData(DLCItem dlc)
        {
            if (dlc.IsInternal)
            {
                PackedAssets_Internal.Clear();
            }
            else if (dlc.IsNative)
            {
                PackedAssets_Native.Clear();
            }
            PackedAssets_DLC.Clear();
            Builds.Clear();
            Rules.Clear();
            AllDependencies.Clear();
            AllAssets.Clear();
            AllBundles.Clear();
            AllSharedBundles.Clear();

            //建立其他文件
            List <BuildRuleConfig> tempBuildDatas = dlc.BuildRuleData;

            if (tempBuildDatas == null && tempBuildDatas.Count == 0)
            {
                CLog.Error("没有配置相关的AssetBundle信息");
                return(null);
            }

            foreach (var item in tempBuildDatas)
            {
                BuildRule buildRule = null;
                if (item.BuildRuleType == BuildRuleType.Directroy)
                {
                    buildRule = new BuildAssetsWithDirectroy(dlc, item);
                }
                else if (item.BuildRuleType == BuildRuleType.FullPath)
                {
                    buildRule = new BuildAssetsWithPath(dlc, item);
                }
                else if (item.BuildRuleType == BuildRuleType.File)
                {
                    buildRule = new BuildAssetsWithFile(dlc, item);
                }
                Rules.Add(buildRule);
            }

            //搜集依赖的资源
            foreach (var item in Rules)
            {
                CollectDependencies(item.Config.FullSearchPath);
            }
            //打包共享的资源
            BuildSharedAssets(dlc);

            foreach (var item in Rules)
            {
                item.Build();
            }
            EditorUtility.ClearProgressBar();
            return(Builds);
        }
    //无规则设置bundle名称             路径              修改路径的方法                                             bundle的名字
    static void InternalSetBundleName(string path, Func <string, string> modifyPath, AssetImporter importer = null, string bundleName = null)
    {
        if (importer == null)
        {
            importer = AssetImporter.GetAtPath(path);
        }
        if (string.IsNullOrEmpty(bundleName))
        {
            bundleName = modifyPath(path);
        }
        //如果bundleName有后缀,需要删除
        string extension = Path.GetExtension(bundleName);

        if (!string.IsNullOrEmpty(extension))
        {
            bundleName = bundleName.Replace(extension, "");
        }
        string    file_name = bundleName;
        BuildRule rule      = BundleBuildRule.MatchRule(path);

        if (rule != null)
        {
            bundleName = rule.GetBundleName(bundleName);
        }
        if (bundleName.Contains("Material"))
        {
            //针对UI
            int index = bundleName.IndexOf("Material");
            bundleName = bundleName.Substring(0, index - 1);
        }
        else if (bundleName.Contains("Materials"))
        {
            //针对模型导入
            int index = bundleName.IndexOf("Materials");
            bundleName = bundleName.Substring(0, index - 1);
        }
        if (bundleName.Contains(" "))
        {
            Debug.LogError("当前bundleName存在空格 : " + bundleName);
            return;
        }

        importer.assetBundleName = bundleName + ABPathHelper.Unity3dSuffix;
    }
    //通过规则设置Bundle的名称
    static void InternalSetBundleNameByRule(string path, Func <string, string> modifyPath, AssetImporter importer = null, string bundleName = null)
    {
        if (importer == null)
        {
            importer = AssetImporter.GetAtPath(path);
        }
        if (string.IsNullOrEmpty(bundleName))
        {
            bundleName = modifyPath(path);
        }
        string extension = Path.GetExtension(bundleName);

        if (string.IsNullOrEmpty(extension) == false)
        {
            bundleName = bundleName.Replace(extension, "");
        }
        string    file_name = bundleName;
        BuildRule rule      = BundleBuildRule.MatchRule(path);

        if (rule != null)
        {
            bundleName = rule.GetBundleName(bundleName);
        }
        if (bundleName.Contains("Material"))
        {
            int index = bundleName.IndexOf("Material");
            bundleName = bundleName.Substring(0, index - 1);
        }
        else if (bundleName.Contains("Materials"))
        {
            //针对模型导入
            int index = bundleName.IndexOf("Materials");
            bundleName = bundleName.Substring(0, index - 1);
        }
        if (string.IsNullOrEmpty(bundleName))
        {
            importer.assetBundleName = string.Empty;
        }
        else
        {
            importer.assetBundleName = bundleName + ABPathHelper.Unity3dSuffix;
        }
    }
示例#4
0
    public static List <BuildRule> GetBuildRules(bool isReloadRule = false)
    {
        if (!isReloadRule && _rules != null && _rules.Count > 0)
        {
            return(_rules);
        }

        _rules.Clear();

        var ruleFile = Application.dataPath + "/../buildrules.txt";
        var str      = File.ReadAllText(ruleFile);
        var rules    = str.Split('\n');

        foreach (var item in rules)
        {
            BuildRule rule  = new BuildRule();
            var       param = item.Split('#');
            if (param.Length < 3)
            {
                continue;
            }

            rule.inPut  = param[0].Trim();
            rule.outPut = param[2].Trim();

            var pattens = param[1].Split(',');
            foreach (var patten in pattens)
            {
                rule.pattens.Add(patten.Trim());
            }

            _rules.Add(rule);
        }

        return(_rules);
    }
示例#5
0
 static void AddRule(string folder, string specifyName, EBuildRule rule)
 {
     _buildRules[folder] = new BuildRule(folder, specifyName, rule);
 }