/// <summary> /// 读取到json配置 并存储起来 /// </summary> /// <param name="jsonPath">json的路径</param> private void AnalysisJsonAndSave(string jsonName) { TextAsset jsonstring = null; KeyValueInfo keyValueInfo = null; if (string.IsNullOrEmpty(jsonName)) { return; } jsonstring = Resources.Load <TextAsset>(jsonName); keyValueInfo = JsonMapper.ToObject <KeyValueInfo>(jsonstring.text); foreach (var item in keyValueInfo.KeyValueList) { _AppJsonSetting.Add(item.Key, item.Value); } }
/// <summary> /// 将打包的ab数据配置存储更新 /// </summary> /// <param name="keyValue"></param> public static void DataToJson(string path, KeyValueInfo kvInfo) { if (string.IsNullOrEmpty(path) || kvInfo == null) { return; } string abstr = JsonMapper.ToJson(kvInfo); try { //覆盖写入 System.IO.File.WriteAllText(Application.dataPath + "/Resources/" + path, abstr); } catch (Exception e) { Debug.LogError(e.GetType() + "-" + e.Message); } }
public static void SetABLabels() { keyValueList = new KeyValueInfo(); keyValueList.KeyValueList = new List <KeyValueNode>(); keyValueList.KeyValueList.Clear(); //需要给AB做标记的根目录 string strNeedSetABLableRootDIR = ""; //目录信息 DirectoryInfo[] dirScenesDIRArray = null; //清空无用AB标记 AssetDatabase.RemoveUnusedAssetBundleNames(); //定位需要打包资源的文件夹根目录。 strNeedSetABLableRootDIR = PathManger.GetABResoursesPath(); DirectoryInfo dirTempInfo = new DirectoryInfo(strNeedSetABLableRootDIR); dirScenesDIRArray = dirTempInfo.GetDirectories(); //遍历每个“场景”文件夹(目录) foreach (DirectoryInfo currentDIR in dirScenesDIRArray) { //遍历本场景目录下的所有的目录或者文件, //如果是目录,则继续递归访问里面的文件,直到定位到文件。 string tmpScenesDIR = strNeedSetABLableRootDIR + "/" + currentDIR.Name; //res/** DirectoryInfo tmpScenesDIRInfo = new DirectoryInfo(tmpScenesDIR); //场景目录信息res/**/** int tmpIndex = tmpScenesDIR.LastIndexOf("/"); string tmpScenesName = tmpScenesDIR.Substring(tmpIndex + 1); //场景名称 //递归调用与处理目录或文件系统,如果找到文件,修改AssetBundle 的标签(label) JudgeDIROrFileByRecursive(currentDIR, tmpScenesName); }//foreach_end //将生成的bundle名与资源名添加到json文件 JsonConfigManger.DataToJson(PathManger.jsonInfoPath, keyValueList); Debug.Log("Json数据配置完成!"); //刷新 AssetDatabase.Refresh(); //提示 Debug.Log("AssetBundles 标签设置完成!"); }