/// <summary> /// 导入tab.config /// tab表只有一个记录已经打开的tab及其位置 /// </summary> public static string[,] LoadTabConfig(string tabConfigPath) { //VLog.I("test1"); //这里要把二进制数据转成按顺序存储的string[,]然后返回去 byte[] bs = FileHelper.Get(tabConfigPath); IoBuffer ib = new IoBuffer(); ib.PutBytes(bs); int len = ib.GetInt(); //VLog.I("test2--->len:"+bs.Length); string[,] ss = new string[len, 2]; List <TempTabData> _TabList = new List <TempTabData>(); for (int i = 0; i < len; i++) { TempTabData data = new TempTabData(); data.Name = ib.GetString(); data.RefName = ib.GetString(); data.Index = ib.GetInt(); _TabList.Add(data); } _TabList.Sort(new TabDataCom()); for (int j = 0; j < len; j++) { ss [j, 0] = _TabList [j].Name; ss [j, 1] = _TabList [j].RefName; //VLog.I("GEditorDataMgr","LoadTabConfig","j:"+j+" Name:"+ss[j, 0]+" RefName:"+ss [j, 1]); } return(ss); }
public static void LoadDataTable(string tablePath) { byte[] bs = FileHelper.ReadBytesFromFile(tablePath); buffer.PutBytes(bs); string tableName = buffer.GetString(); StaticDataTable dataTable = new StaticDataTable(tableName); if (TableDic.ContainsKey(tableName)) { Debug.LogError("TableMgr.LoadDataTable table:" + tableName + "已存在,导入失败"); return; } dataTable.Column = buffer.GetInt(); dataTable.Row = buffer.GetInt(); Debug.LogError("TableMgr.LoadDataTable tableName:" + tableName + " row:" + dataTable.Row + " colomn:" + dataTable.Column); dataTable.TableDataArray = new string[dataTable.Row, dataTable.Column]; for (int i = 0; i < dataTable.Row; i++) { for (int j = 0; j < dataTable.Column; j++) { string fieldContent = buffer.GetString(); dataTable.TableDataArray[i, j] = fieldContent; Debug.Log("TableMgr.LoadDataTable i:" + i + " j:" + j + " fieldContent:" + fieldContent); } } for (int i = 0; i < dataTable.Column; i++) { //Debug.LogError("nani-->i:"+i+" "+ dataTable.TableDataArray[0, i]); dataTable.FieldNameDic.Add(dataTable.TableDataArray[0, i], i); } for (int i = 0; i < dataTable.Row; i++) { dataTable.IDDic.Add(dataTable.TableDataArray[i, 0], i); } TableDic.Add(tableName, dataTable); buffer.Clear(); }
/// <summary> /// 获取stream中resInfoList /// </summary> private void ReadStreamResInfoList() { Utils.SB.Append(UnityUtil.StreamingAssetsPath); Utils.SB.Append("/resInfoList.bytes"); string resInfoListPathInStream = Utils.SB.ToString(); Utils.ClearSB(); LogMgr.I("UnCompress", "ReadSteamResInfoList.onSuccess", "开始读取包内resInfoList path:" + resInfoListPathInStream, BeShowLog); //读取stream里资源描述列表 Action <byte[]> onSuccess = (bs) => { IoBuffer ib = new IoBuffer(102400); ib.PutBytes(bs); int count = ib.GetInt(); LogMgr.I("UnCompress", "ReadSteamResInfoList.onSuccess", "读取包内resInfoList成功 资源数:" + count, BeShowLog); for (int i = 0; i < count; i++) { string relePath = ib.GetString(); string hash = ib.GetString(); resInfoDicInStream.Add(relePath, hash); } SetState(UnCompressState.unCompressStreamRes); }; Action <string> onFaile = (error) => { LogMgr.E("UnCompress", "ReadSteamResInfoList.onFaile", "读取包内resInfoList失败,解压中断 onFaile error:" + error, BeShowLog); }; FileHelper.GetIns().ReadBytesFromApkFile(resInfoListPathInStream, onSuccess, onFaile); }
public static void LoadCheckDic() { bool b = EditorHelper.BeFileExist(MD5CheckDicPath); if (!b) { return; } if (PathMD5Dic.Count > 0) { PathMD5Dic.Clear(); } var bs = FileHelper.ReadBytesFromFile(MD5CheckDicPath); IoBuffer ib = new IoBuffer(102400); ib.PutBytes(bs); int num = ib.GetInt(); for (int i = 0; i < num; i++) { string relePath = ib.GetString(); string md5 = ib.GetString(); PathMD5Dic.Add(relePath, md5); } }
/// <summary> /// 使用数据创建Tree /// </summary> public void CreateByData(string treeName, RectTransform parentTrm, RectTransform treeRootTrm, float offx, float offy, byte[] data) { Name = treeName; IoBuffer ib = new IoBuffer(); ib.PutBytes(data); bool bFolder = ib.GetBool(); //这里第一个节点一定是根节点,但是还是按正常数据读下 string name = ib.GetString(); int listSize = ib.GetInt(); //VLog.I("TreeContainer","CreateByData","bFolder:"+bFolder+" name:"+name+" listSize:"+listSize); //这里需要创建 TreeRootTrm = treeRootTrm; RootFolder = TreeFolder.CreateRootFolder(treeName, parentTrm, this, offx, offy); for (int i = 0; i < listSize; i++) { //CreateOneItem(ib); bFolder = ib.GetBool(); if (bFolder) { RootFolder.AddFolderByData(ib); } else { RootFolder.AddItemByData(ib); } } }
/// <summary> /// 获取沙盒resInfoList,并存在内存中 /// </summary> private void ReadPersistResInfoList() { Utils.SB.Append(UnityUtil.PersistentPath); Utils.SB.Append("/resInfoList.bytes"); string persisResInfoListPath = Utils.SB.ToString(); Utils.ClearSB(); byte[] bs = FileHelper.ReadBytesFromFile(persisResInfoListPath); IoBuffer ib = new IoBuffer(); ib.PutBytes(bs); int num = ib.GetInt(); LogMgr.I("DownloadRes", "CompareResInfoListPersist_Remote", "获取沙盒resInfoList res num:" + num + " path:" + persisResInfoListPath, BeShowLog); for (int i = 0; i < num; i++) { string keyRelePath = ib.GetString(); string valueHash = ib.GetString(); //LogMgr.I("DownloadRes", "CompareResInfoListPersist_Remote", " keyRelePath:"+ keyRelePath, BeShowLog); PersisResInfoDic.Add(keyRelePath, valueHash); } SetState(DownloadResState.compareResInfoListPersist_Remote); }
/// <summary> /// 拉取远程cdn资源描述列表 /// </summary> private void PullRemoteResInfoList() { Action <byte[]> onSuccess = (bs) => { IoBuffer ib = new IoBuffer(); ib.PutBytes(bs); int num = ib.GetInt(); LogMgr.I("DownloadRes", "PullRemoteResInfoList", " 获取remote resInfoList成功 资源数:" + num, BeShowLog); for (int i = 0; i < num; i++) { string keyRelePath = ib.GetString(); string valueHash = ib.GetString(); RemoteResInfoDic.Add(keyRelePath, valueHash); } SetState(DownloadResState.readPersistResInfoList); }; Action <string> onFaile = (error) => { LogMgr.E("DownloadRes", "PullRemoteResInfoList", "下载流程中断 获取remote resInfoList失败", BeShowLog); }; Utils.SB.Append(UpdateMgr.RemoteCdnUrl); Utils.SB.Append("/"); Utils.SB.Append(UnityUtil.CurPlatform); Utils.SB.Append("/resInfoList.bytes"); string remoteResInfoListPath = Utils.SB.ToString(); Utils.ClearSB(); LogMgr.I("DownloadRes", "PullRemoteResInfoList", "开始拉取remote resInfoList url:" + remoteResInfoListPath, BeShowLog); FileHelper.GetIns().ReadBytesFromApkFile(remoteResInfoListPath, onSuccess, onFaile); }
/// <summary> /// 使用外部数据填充增加folder /// </summary> /// <param name="ib">Ib.</param> public void AddFolderByData(IoBuffer ib) { bool bFolder = false; string name = ib.GetString(); int listSize = ib.GetInt(); if (!BeFolderOpen) { OpenFolder(); } TreeFolder curTreeFolder = TreeFolder.CreateSubFolder(name, this, MyTreeContainer); for (int i = 0; i < listSize; i++) { //CreateOneItem(ib); bFolder = ib.GetBool(); if (bFolder) { curTreeFolder.AddFolderByData(ib); } else { curTreeFolder.AddItemByData(ib); } } }
private void OnPost(HttpRequest request) { byte[] cacheBs = new byte[102400]; int len = request.ClientSocket.Receive(cacheBs); byte[] bs = new byte[len]; Array.Copy(cacheBs, 0, bs, 0, len); //Debug.Log("服务端接受len :" + bs.Length); //for (int i = 0; i < bs.Length; i++) //{ // Debug.LogError("server rec: i:"+i+"--->"+bs[i]); //} //用于存储消息长度int的bytes byte[] msgContentLenBytes = new byte[4]; Array.Copy(bs, bs.Length - 4, msgContentLenBytes, 0, 4); IoBuffer ibb = new IoBuffer(1024); ibb.PutBytes(msgContentLenBytes); //真实消息长度 int msgContentLen = ibb.GetInt(); //用于存储去除httpRequest头后的真实消息内容 byte[] msgContentBytes = new byte[msgContentLen]; //Debug.LogError("server rec msgContentLen:" + msgContentLen); Array.Copy(bs, bs.Length - msgContentLen - 4, msgContentBytes, 0, msgContentLen); IoBuffer buffer = new IoBuffer(10240); buffer.PutBytes(msgContentBytes); string s = buffer.GetString(); if (BeWriteLog2File) { WriteString2File_Append(LogFileSavePath, s); } Debug.Log(s); request.ClientSocket.Send(Encoding.UTF8.GetBytes(HttpResponse.ResponseHead)); request.ClientSocket.Close(); request.ClientSocket = null; }
void Start() { if (FileHelper.BeFileExists(OutputURL)) { File.Delete(OutputURL); } byte[] bs = FileHelper.Get(InputURL); Log.i("bs.len:" + bs.Length); IoBuffer buffer = new IoBuffer(1000000); buffer.PutBytes(bs); int dataNum = buffer.GetInt(); FileHelper.WriteMessage(OutputURL, "数据条数:" + dataNum); do { if (BeTest) { string key = buffer.GetString();//key //这句代表一个treeItem的开头 if (key.Equals("ID")) { FileHelper.WriteMessage(OutputURL, "----------------分割线---------------"); } string value = buffer.GetString(); //value string type = buffer.GetString(); //type string s = "[" + key + "][" + value + "][" + type + "]"; FileHelper.WriteMessage(OutputURL, s); } else { string value1 = buffer.GetString(); FileHelper.WriteMessage(OutputURL, value1); } }while (buffer.HasData()); Log.i("数据查看器生成数据完毕"); }
/// <summary> /// 导入已经存在的场景 /// 先导入data/bin/文件夹下的场景数据文件 /// 然后根据这个数据文件的id依次加载 "Prefabs/Scenes/scn"+sceneIdStr 这个路径下的各个场景文件 /// </summary> /// <param name="id">Identifier.</param> void LoadScene(int id) { Debug.Log(string.Format("开始导入场景{0}数据", id)); string sceneInfoPath = Path.GetDirectoryName(Application.dataPath) + "/data/bin/"; StringBuilder _path = new StringBuilder(); _path.Append(sceneInfoPath); _path.Append("scn"); _path.Append(id); byte[] bytes = FileHelper.ReadBytesFromFile(_path.ToString()); //Debug.Log("导入时buffer长度:" + bytes.Length); if (null == bytes) { Debug.LogError(string.Format("error!! 获取地图:{0}失败", _path.ToString())); return; } IoBuffer buffer = new IoBuffer(); buffer.PutBytes(bytes); //场景ID byte sceneId = buffer.GetByte(); sceneIdStr = sceneId.ToString(); //场景名 sceneNameStr = buffer.GetString(); //场景宽 int mapWidth = buffer.GetInt(); mapWidthStr = mapWidth.ToString(); //场景高 int mapHeight = buffer.GetInt(); mapHeightStr = mapHeight.ToString(); _path = null; Debug.Log(string.Format("导入场景{0}信息成功", sceneId)); CleanScene(); //scnPrefab路径,导出时需要,载入不需要 //string scnPrefabPath = Application.dataPath+"/Resources/Prefabs/Scenes/scn"+sceneIdStr; Debug.Log("开始载入场景" + sceneIdStr + "资源"); //创建新地图 GameObject goScene = Instantiate(Resources.Load("Prefabs/Scenes/scn" + sceneIdStr + "/scene")) as GameObject; if (null == goScene) { Debug.LogError("找不到" + "Prefabs/Scenes/scn" + sceneIdStr + "/scene文件 停止终止!!"); return; } goScene.name = "scene"; GameObject goTerrain = Instantiate(Resources.Load("Prefabs/Scenes/scn" + sceneIdStr + "/terrain")) as GameObject; if (null == goTerrain) { Debug.LogError("找不到" + "Prefabs/Scenes/scn" + sceneIdStr + "/terrain文件 停止终止!!"); return; } goTerrain.name = "terrain"; GameObject goLight = Instantiate(Resources.Load("Prefabs/Scenes/scn" + sceneIdStr + "/dlight")) as GameObject; if (null == goLight) { Debug.LogError("找不到" + "Prefabs/Scenes/scn" + sceneIdStr + "/dlight文件 停止终止!!"); return; } goLight.name = "dlight"; GameObject goTree = Instantiate(Resources.Load("Prefabs/Scenes/scn" + sceneIdStr + "/tree")) as GameObject; if (null == goTree) { Debug.LogError("找不到" + "Prefabs/Scenes/scn" + sceneIdStr + "/tree文件 停止终止!!"); return; } goTree.name = "tree"; GameObject goObj = Instantiate(Resources.Load("Prefabs/Scenes/scn" + sceneIdStr + "/obj")) as GameObject; if (null == goObj) { Debug.LogError("找不到" + "Prefabs/Scenes/scn" + sceneIdStr + "/obj文件 停止终止!!"); return; } goObj.name = "obj"; GameObject goAni = Instantiate(Resources.Load("Prefabs/Scenes/scn" + sceneIdStr + "/ani")) as GameObject; if (null == goAni) { Debug.LogError("找不到" + "Prefabs/Scenes/scn" + sceneIdStr + "/ani文件 停止终止!!"); return; } goAni.name = "ani"; GameObject goPartical = Instantiate(Resources.Load("Prefabs/Scenes/scn" + sceneIdStr + "/partical")) as GameObject; if (null == goPartical) { Debug.LogError("找不到" + "Prefabs/Scenes/scn" + sceneIdStr + "/partical文件 停止终止!!"); return; } goAni.name = "ani"; goPartical.name = "partical"; //info = "导入地图"+sceneIdStr+"成功"; Debug.Log(string.Format("导入场景{0}成功", sceneId)); }