Esempio n. 1
0
    public VerInfo BuildRes(string rootPath, BuildTarget traget, BuildAssetBundleOptions options)
    {
        if (string.IsNullOrEmpty(m_BuildResInfo.ResParentPath))
        {
            return(null);
        }
        Dictionary <string, AssetBundleBuild> maps = new Dictionary <string, AssetBundleBuild>();

        BuildAB.HandleBundleAB(AppConst.ABPath + m_BuildResInfo.ResParentPath, ref maps);
        List <AssetBundleBuild> list = new List <AssetBundleBuild>();
        ResCfg resCfg = null;

        if (File.Exists(AppConst.CoreDef.EditorResCfgPath))
        {
            TextAsset resCfgtext = AssetDatabase.LoadAssetAtPath <TextAsset>(AppConst.CoreDef.EditorResCfgPath);
            resCfg = JsonUtility.FromJson <ResCfg>(resCfgtext.text);
        }
        foreach (string abName in maps.Keys)
        {
            AssetBundleBuild abb   = maps[abName];
            List <string>    files = new List <string>();
            foreach (string file in abb.assetNames)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (name == "defaultres" || (resCfg != null && resCfg.GetResInfo(name) != null))
                {
                    files.Add(file);
                }
                else
                {
                    Debug.LogError("有文件放在ab文件夹下  但是没有加入到配置表" +
                                   ",可能是无效的资源将不被打包到ab abName=" + name);
                }
            }
            abb.assetNames = files.ToArray();
            list.Add(abb);
        }

        BuildPipeline.BuildAssetBundles(rootPath, list.ToArray(), options, traget);
        CompressFiles(list);
        return(BuildFileTxt(list));
    }
Esempio n. 2
0
    public static bool Update()
    {
        bool ret = false;

        if (resInfo == null)
        {
            return(ret);
        }
        if (loaclFileresInfo == null || loaclFileresInfo.groups.Count != resInfo.groups.Count || loaclFileresInfo.resources.Count != resInfo.resources.Count)
        {
            ret = true;
        }
        else
        {
            if (loaclFileresInfo == null || loaclFileresInfo.groups.Count == resInfo.groups.Count)
            {
                foreach (ResGroupCfg da in loaclFileresInfo.groups)
                {
                    bool flag = false;
                    foreach (ResGroupCfg da2 in resInfo.groups)
                    {
                        if (da.sceneName == da2.sceneName)
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        ret = true;
                        break;
                    }
                }
            }
            if (loaclFileresInfo == null || loaclFileresInfo.resources.Count == resInfo.resources.Count)
            {
                foreach (ResInfoData da in loaclFileresInfo.resources)
                {
                    ResInfoData da2 = resInfo.GetResInfo(da.name);
                    if (da.IsDirty(da2))
                    {
                        ret = true; break;
                    }
                }
            }
        }

        if (ret)
        {
            string jsonstr = JsonUtility.ToJson(resInfo, true);
            loaclFileresInfo = JsonUtility.FromJson <ResCfg>(jsonstr);
            if (!System.IO.Directory.Exists(Path.GetDirectoryName(ResCfgFilePath)))
            {
                System.IO.Directory.CreateDirectory(Path.GetDirectoryName(ResCfgFilePath));
            }
            File.WriteAllText(ResCfgFilePath, jsonstr);
            UnityEditor.AssetDatabase.SaveAssets();
            UnityEditor.AssetDatabase.Refresh();
            RefreshGroupList();
        }

        return(ret);
    }