Example #1
0
 /// <summary>
 /// 加载资源需要的配置信息
 /// </summary>
 public void LoadResCfg()
 {
     if (File.Exists(AppConst.CoreDef.CfgExternalFileName))
     {
         if (resCfg == null)
         {
             Debug.LogError("无法加载到资源配置表");
         }
         else
         {
             AssetBundle ab         = AssetBundle.LoadFromFile(AppConst.CoreDef.CfgExternalFileName);
             TextAsset   txt        = ab.LoadAsset <TextAsset>(AppConst.CoreDef.CfgAssetName);
             string      resCfgtext = txt.text;
             if (resCfgtext == null)
             {
                 Debug.LogError("无法加载到资源配置表2");
             }
             else
             {
                 resCfg = JsonUtility.FromJson <ResCfg>(resCfgtext);
             }
             ab.Unload(true);
         }
     }
     else
     {
         Debug.LogError("不存在资源配置表");
     }
 }
Example #2
0
    /// <summary>
    /// 初始化配置
    /// </summary>
    public void Init()
    {
        if (!AppConst.DebugMode)
        {
            LoadResCfg();
        }
        else
        {
#if UNITY_EDITOR
            TextAsset resCfgtext = AssetDatabase.LoadAssetAtPath <TextAsset>(AppConst.CoreDef.EditorResCfgPath);
            if (resCfgtext == null)
            {
                Debug.LogError("无法加载到资源配置表2");
            }
            else
            {
                resCfg = JsonUtility.FromJson <ResCfg>(resCfgtext.text);
            }
#endif
        }
        if (resCfg != null)
        {
            foreach (ResInfoData info in resCfg.resources)
            {
                if (!string.IsNullOrEmpty(info.ABName))
                {
                    info.ABName = info.ABName.ToLower();
                }
            }
        }
        localGameCfg = Resources.Load <LocalGameCfgData>("gamecfg");
        localGameCfg.Init();
    }
Example #3
0
 public static void Refresh()
 {
     if (loaclFileresInfo != null)
     {
         resInfo = JsonUtility.FromJson <ResCfg>(JsonUtility.ToJson(loaclFileresInfo));
     }
     RefreshGroupList();
 }
Example #4
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));
    }
Example #5
0
 /// <summary>
 /// 重新查找所有资源
 /// </summary>
 public static void Rebuild()
 {
     if (File.Exists(ResCfgFilePath))
     {
         string json = File.ReadAllText(ResCfgFilePath);
         if (!string.IsNullOrEmpty(json))
         {
             loaclFileresInfo = JsonUtility.FromJson <ResCfg>(json);
         }
         else
         {
             resInfo = new ResCfg();
         }
         Refresh();
     }
     else
     {
         resInfo = new ResCfg();
     }
     RefreshGroupList();
 }
Example #6
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);
    }