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> /// 获取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 void AddItem() { InputTextDialog.Open( delegate(byte[] bts) { //创建文件夹 IoBuffer ib = new IoBuffer(); ib.PutBytes(bts); string inputFieldText = ib.GetString(); if (!BeFolderOpen) { OpenFolder(); //没打开的先打开再创建,否则位置错乱 } var ti = TreeItem.Create(inputFieldText, this, MyTreeContainer); //nafio add 170623 这段代码有点冗余应该赋值一次就可以,类似重复的代码也需要整理下 // if (null != MyMenuList.CurSelItem && // !MyMenuList.CurSelItem.Equals (ti)) // { // MyMenuList.CurSelItem.DeSelect(); // } ti.TreeItemID = GEditorRoot.GetIns().KVContainerDic[MyTreeContainer.Name].CreateKVList(MyTreeContainer.Name); MyTreeContainer.CurSelItem = ti; //ti.OnSelect (); Log.i("TreeFolder", "AddItem", "新建item name:" + inputFieldText + " id:" + ti.TreeItemID, BeShowLog); } ); }
/// <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> /// 使用数据创建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> /// 拉取远程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); }
public void Send(Cmd4Send cmd) { ClientSendBuffer.Clear(); ClientSendBuffer.PutShort(MSG_HEAD); byte[] content = cmd.Encode(); int len = content.Length + 2;//+2是cmd的short长度 ClientSendBuffer.PutInt(len); ClientSendBuffer.PutShort(cmd.Cmd); ClientSendBuffer.PutBytes(content); byte[] bs = ClientSendBuffer.ToArray(); //Debug.Log("发送长度:"+bs.Length); //IoBuffer ib = new IoBuffer(102400); //ib.PutBytes(bs); //short head = ib.GetShort(); //int len0 = ib.GetInt(); //int cmd0 = ib.GetShort(); //int contentI = ib.GetInt(); //string contentS = ib.GetString(); //Debug.Log("head:"+head+" len0:"+len0+" cmd0:"+cmd0+" contentI:"+contentI+" contentS:"+contentS); Send(bs); }
/// <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 override void Decode(byte[] bs) { Debug.Log("Cmd4RecKB.Decode"); IoBuffer buffer = new IoBuffer(1024); buffer.PutBytes(bs); string key = buffer.GetString(); ServerMgr.Ins.ProcessKB(key); }
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(); }
private void AddItem() { InputTextDialog.Open( delegate(byte[] bts) { //创建文件夹 IoBuffer ib = new IoBuffer(); ib.PutBytes(bts); string name = ib.GetString(); string _itemID = GEditorRoot.GetIns().KVContainerDic[MyTreeContainer.Name].CreateKVList(MyTreeContainer.Name); var treeItem = InsertItem(IndexInParentFolder, name, ParentFolder, MyTreeContainer); treeItem.TreeItemID = _itemID; Log.i("TreeItem", "AddItem", "新建item name:" + name + " id:" + _itemID, BeShowLog); } ); }
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; }
/// <summary> /// 新增文件夹 /// </summary> public void AddFolder() { InputTextDialog.Open( delegate(byte[] bts) { //创建文件夹 IoBuffer ib = new IoBuffer(); ib.PutBytes(bts); string inputFieldText = ib.GetString(); if (!BeFolderOpen) { OpenFolder(); //没打开的先打开再创建,否则位置错乱 } TreeFolder.CreateSubFolder(inputFieldText, this, MyTreeContainer); } ); }
public void Send(string sessionID, Cmd4Send cmd) { Debug.Log("服务端向sessionID:" + sessionID + " 发送 cmd:" + cmd.Cmd); if (SessionDic.ContainsKey(sessionID)) { ServerSendBuffer.Clear(); ServerSendBuffer.PutShort(MSG_HEAD); byte[] content = cmd.Encode(); int len = content.Length + 2;//+2是cmd的short长度 ServerSendBuffer.PutInt(len); ServerSendBuffer.PutShort(cmd.Cmd); ServerSendBuffer.PutBytes(content); byte[] bs = ServerSendBuffer.ToArray(); AsyncSend(SessionDic[sessionID]._SocketPackMgr._Socket, bs); } }
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> /// 接受dialog返回数据 /// </summary> /// <param name="bs">Bs.</param> private void OnDialogReturnValue(byte[] bs) { IoBuffer _ib = new IoBuffer(); _ib.PutBytes(bs); string _key = _ib.GetString(); //从输入框返回要修改的key值 string _value = _ib.GetString(); //从输入框返回的要修改的value值 string _type = _ib.GetString(); //从输入框返回的修改类型值,比如字符串类型,或者列表类型 string _TreeItemIDStr = TreeItemID.ToString(); //Log.i("KVListItem", "OnDialogReturnValue", "=======>iNDEX:" + Index, BeShowLog); _MyKVContainer.ModifyKVItem(_TreeItemIDStr, Index, _key, _value, _type); _ib.Clear(); _ib = null; }
public void ReName() { //base.ReName (); InputTextDialog.Open( delegate(byte[] bts) { //创建文件夹 IoBuffer ib = new IoBuffer(); ib.PutBytes(bts); string newName = ib.GetString(); Name = newName;//这个名称不设置的化,当重命名后,再复制黏贴就出问题,显示的是未改名前的名称 ResizeTextRect(newName); //刷TreeContainer的W.这里w的算法,跟上面Create中一致 float _w = this.CurItemLeftOffset + UIEnum.ItemImageW + 4 + UIEnum.ItemImageW + Tools.GetStringW(this.ItemNameText.text, UIEnum.FontSize); MyTreeContainer.SetTreeW(_w); MyTreeContainer.RefreshTreeArea(); } ); }
public void Post(short cmd, byte[] bytes, Action <byte[]> callback) { _Buffer.Clear(); _Buffer.PutBytes(bytes); //NINFO 这个为了帮助server去掉client httpRequest头 int msgContentLen = _Buffer.GetLength(); _Buffer.PutInt(msgContentLen); byte[] bs = _Buffer.ToArray(); //Debug.Log("客户端发送len :" + bs.Length+" msgContentLen:"+msgContentLen); //for (int i = 0; i < bs.Length; i++) //{ // Debug.LogError("client send: i:" + i + "--->" + bs[i]); //} StartCoroutine(Post(bs, callback, false)); }
//TODO 这个方法并没有使用和实现,目前实现方法是 //首次从TabContainer.OPENED_EDITORS读默认打开的编辑器,关闭时保存打开编辑器数据到配置文件 //非首次的化就从配置文件读取(已经打开的编辑器) /// <summary> /// 使用(已存在)数据构建Tab结构 /// 由外部负责找到数据,ui框架本身不负责查找数据的具体业务 /// </summary> /// <param name="bs">Bs.</param> public void BuildByData(byte[] bs) { IoBuffer ib = new IoBuffer(); ib.PutBytes(bs); }
/// <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)); }