/// <summary> /// 添加资源 /// </summary> /// <param name="resource"></param> public void Add(ref ResInfo resource) { if (!Resources.Contains(resource)) { Resources.Add(resource); } }
/// <summary> /// 合并 /// </summary> /// <param name="other"></param> public void MergeWithOther(ResPackConfig other) { if (_resourceMap == null || other == null) { return; } //先清理 for (int i = 0; i < other.PackInfo.Count; ++i) { ResPackInfo resPackInfo = other.PackInfo[i]; // for (int j = PackInfo.Count - 1; j >= 0; j--) { if (PackInfo[j].Path == resPackInfo.Path) { PackInfo.RemoveAt(j); } } } //添加 for (int i = 0; i < other.PackInfo.Count; ++i) { ResPackInfo resPackInfo = other.PackInfo[i]; PackInfo.Add(resPackInfo); List <ResInfo> resInfos = resPackInfo.Resources; for (int resIndex = 0; resIndex < resInfos.Count; ++resIndex) { ResInfo res = resInfos[resIndex]; if (!_resourceMap.ContainsKey(res.Path)) { _resourceMap.Add(res.Path, resPackInfo); } else { //Log.LogE("Pack Config {0} and {1}:{2}had same res : {3}", "Main", "Other", resPackInfo.Path, res.Path); //替换 Log.LogD("Reload ResPackInfo:"); _resourceMap.Remove(res.Path); _resourceMap.Add(res.Path, resPackInfo); } } } //后处理下依赖 for (int i = 0; i < PackInfo.Count; ++i) { ResPackInfo resPackInfo = PackInfo[i]; if (resPackInfo != null) { resPackInfo.ProcessDependency(this.PackInfo); } } }
/// <summary> /// 单个资源是否在外磁盘 /// </summary> /// <param name="path"></param> /// <returns></returns> public bool IsOutside(string path) { for (int i = 0; i < Count; i++) { ResInfo r = Resources[i]; if (r.Path.Equals(path, System.StringComparison.OrdinalIgnoreCase)) { return(r.Outside); } } return(false); }
/// <summary> /// 位置检查 /// </summary> /// <returns></returns> protected override bool CheckLocation() { if (!base.CheckLocation()) { bool outside = FileUtil.IsExistInIFSExtraFolder(Path); //内部资源都标记在外面 for (int i = 0; i < Count; i++) { ResInfo r = Resources[i]; r.Outside = outside; } } return(true); }
/// <summary> /// 添加资源映射 /// </summary> /// <param name="packInfo"></param> void AddToMap(ResPackInfo packInfo) { for (int i = 0; i < packInfo.Resources.Count; i++) { ResInfo r = packInfo.Resources[i]; try { _resourceMap.Add(r.Path, packInfo); } catch (Exception e) { JW.Common.Log.LogE("Add {0} to map error:{1}", r.Path, e.Message); } } }
/// <summary> /// 读二进制 配置初始化 /// </summary> /// <param name="data"></param> /// <param name="offset"></param> public virtual void Read(byte[] data, ref int offset) { // Path Path = MemoryOperator.ReadString(data, ref offset); // resource count int count = MemoryOperator.ReadShort(data, ref offset); // resources for (int i = 0; i < count; i++) { ResInfo resource = new ResInfo(); resource.Path = MemoryOperator.ReadString(data, ref offset); resource.Ext = MemoryOperator.ReadString(data, ref offset); Resources.Add(resource); } // check location CheckLocation(); }