static unsafe FakeStructArray SaveSprites(DataBuffer buffer, List <Sprite> sprites) { FakeStructArray array = new FakeStructArray(buffer, SpriteDataS.ElementSize, sprites.Count); float tx = sprites[0].texture.width; float ty = sprites[0].texture.height; for (int i = 0; i < sprites.Count; i++) { var sprite = sprites[i]; string name = sprite.name; SpriteDataS *sp = (SpriteDataS *)array[i]; sp->name = buffer.AddData(name); var sr = sp->rect = sprite.rect; sp->pivot = sprite.pivot; float w = sprite.texture.width; float h = sprite.texture.height; float x = sr.x; float rx = sr.width + x; float y = sr.y; ty = sr.height + y; x /= w; rx /= w; y /= h; ty /= h; sp->uv0.x = x; sp->uv0.y = y; sp->uv1.x = x; sp->uv1.y = ty; sp->uv2.x = rx; sp->uv2.y = ty; sp->uv3.x = rx; sp->uv3.y = y; } return(array); }
/// <summary> /// 从缓存中读取布局信息 /// </summary> /// <param name="fake">数据缓存</param> /// <param name="index">索引位置</param> public void LoadFromBuffer(FakeStructArray fake, int index) { Left = layout.GetLine(fake[index, 0]); Right = layout.GetLine(fake[index, 1]); Top = layout.GetLine(fake[index, 2]); Down = layout.GetLine(fake[index, 3]); }
unsafe static void LoadChild(Transform root, DataBuffer db, FakeStructArray array) { var c = root.childCount; for (int i = 0; i < c; i++) { var t = root.GetChild(c); var name = t.name; int l = array.Length; for (int j = 0; j < l; j++) { LocalCoordinates *lc = (LocalCoordinates *)array[j]; string str = db.GetData(lc->Name) as string; if (str == name) { t.localPosition = lc->Postion; t.localRotation = lc->Rotate; t.localScale = lc->Scale; var arr = db.GetData(lc->Child) as FakeStructArray; if (arr != null) { LoadChild(t, db, arr); } } } } }
/// <summary> /// 存储布局信息 /// </summary> /// <param name="fake">数据缓存</param> /// <param name="index">索引位置</param> public void SaveToDataBuffer(FakeStructArray fake, int index) { fake[index, 0] = layout.GetLineID(Left); fake[index, 1] = layout.GetLineID(Right); fake[index, 2] = layout.GetLineID(Top); fake[index, 3] = layout.GetLineID(Down); }
static void QueryRoom(KcpUser linker, DataBuffer buffer) { var list = RoomManager.QueryFreeRoom(); if (list.Count == 0) { ErrorCode.SendErrorCode(linker, ErrorCode.NoFreeRoom); return; } DataBuffer db = new DataBuffer(); FakeStruct fake = new FakeStruct(db, Req.Length); fake[Req.Cmd] = QueryCmd.QueryRoom; fake[Req.Type] = MessageType.Query; db.fakeStruct = fake; int c = list.Count; FakeStructArray array = new FakeStructArray(db, 3, c); for (int i = 0; i < c; i++) { var room = list[i]; array[c, 0] = room.RoomId; array[c, 1] = room.Number; array.SetData(c, 2, room.Name); } fake.SetData(Req.Args, array); linker.Send(AES.Instance.Encrypt(db.ToBytes()), EnvelopeType.AesDataBuffer); }
public FakeStruct CreateData(DataBuffer db) { if (db == null) { db = new DataBuffer(1024); } List <BezierPath> paths = new List <BezierPath>(); var c = transform.childCount; for (int i = 0; i < c; i++) { var path = transform.GetChild(i).GetComponent <BezierPath>(); if (path != null) { paths.Add(path); } } var fake = new FakeStruct(db, 2); fake[0] = db.AddData(name); FakeStructArray array = new FakeStructArray(db, 2, paths.Count); for (int i = 0; i < paths.Count; i++) { var path = paths[i]; array[i, 0] = db.AddData(path.name); array[i, 1] = db.AddArray <Vector3>(GetPathData(path)); } fake[1] = db.AddData(array); return(fake); }
static FakeStructArray SaveCategory(DataBuffer buffer) { FakeStructArray array = new FakeStructArray(buffer, 4, lsc.Count); for (int i = 0; i < lsc.Count; i++) { array.SetData(i, 0, lsc[i].txtName); array.SetData(i, 1, SaveSprites(buffer, lsc[i].sprites)); array.SetInt32(i, 2, lsc[i].width); array.SetInt32(i, 3, lsc[i].height); } return(array); }
/// <summary> /// 储存数据布局信息 /// </summary> /// <param name="db">缓存实例</param> /// <returns></returns> public FakeStruct SaveToDataBuffer(DataBuffer db) { FakeStruct fake = new FakeStruct(db, 2); FakeStructArray fsa = new FakeStructArray(db, 12, lines.Count); for (int i = 0; i < lines.Count; i++) { lines[i].SaveToDataBuffer(fsa, i); } fake.SetData(0, fsa); fsa = new FakeStructArray(db, 4, areas.Count); for (int i = 0; i < areas.Count; i++) { areas[i].SaveToDataBuffer(fsa, i); } fake.SetData(1, fsa); return(fake); }
/// <summary> /// 从布局数据中载入 /// </summary> /// <param name="fake">数据缓存</param> /// <param name="index">索引</param> public void LoadFromBuffer(FakeStructArray fake, int index) { direction = (Direction)fake[index, 0]; Enity.m_sizeDelta.x = fake.GetFloat(index, 1); Enity.m_sizeDelta.y = fake.GetFloat(index, 2); Enity.transform.localPosition = new Vector3(fake.GetFloat(index, 3), fake.GetFloat(index, 4), 0); LineStart = layout.GetLine(fake[index, 5]); LineEnd = layout.GetLine(fake[index, 6]); LoadAdjacentArea(Left, fake.GetData <int[]>(index, 7)); LoadAdjacentArea(Right, fake.GetData <int[]>(index, 8)); LoadAdjacentArea(Top, fake.GetData <int[]>(index, 9)); LoadAdjacentArea(Down, fake.GetData <int[]>(index, 10)); int[] ids = fake.GetData <int[]>(index, 11); if (ids != null) { for (int i = 0; i < ids.Length; i++) { AdjacentLines.Add(layout.GetLine(ids[i])); } } }
static unsafe FakeStructArray SaveChild(Transform root, DataBuffer db) { int c = root.childCount; if (c > 0) { FakeStructArray array = new FakeStructArray(db, LocalCoordinates.ElementSize, c); Int32[] cc = new int[c]; for (int i = 0; i < c; i++) { var a = root.GetChild(i); LocalCoordinates *lc = (LocalCoordinates *)array[i]; lc->Postion = a.localPosition; lc->Rotate = a.localRotation; lc->Scale = a.localScale; lc->Name = db.AddData(a.name); lc->Child = db.AddData(SaveChild(a, db)); } return(array); } return(null); }
/// <summary> /// 存储布局数据 /// </summary> /// <param name="fake"></param> /// <param name="index"></param> public void SaveToDataBuffer(FakeStructArray fake, int index) { fake[index, 0] = (int)direction; fake.SetFloat(index, 1, Enity.m_sizeDelta.x); fake.SetFloat(index, 2, Enity.m_sizeDelta.y); fake.SetFloat(index, 3, Enity.transform.localPosition.x); fake.SetFloat(index, 4, Enity.transform.localPosition.y); fake[index, 5] = layout.GetLineID(LineStart); fake[index, 6] = layout.GetLineID(LineEnd); fake.SetData(index, 7, SaveAdjacentArea(Left)); fake.SetData(index, 8, SaveAdjacentArea(Right)); fake.SetData(index, 9, SaveAdjacentArea(Top)); fake.SetData(index, 10, SaveAdjacentArea(Down)); if (AdjacentLines.Count > 0) { int[] tmp = new int[AdjacentLines.Count]; for (int i = 0; i < tmp.Length; i++) { tmp[i] = layout.GetLineID(AdjacentLines[i]); } fake.SetData(index, 11, tmp); } }
static void GetAllServerIp(KcpUser linker, DataBuffer data) { int index = data.fakeStruct[Req.Args]; var info = ServerTable.GetAllServer(); int c = info.Count; if (c > 0) { DataBuffer db = new DataBuffer(); FakeStruct fake = new FakeStruct(db, Req.Length); fake[Req.Cmd] = ProCmd.AllServer; fake[Req.Type] = MessageType.Pro; FakeStructArray array = new FakeStructArray(db, 3, c); for (int i = 0; i < c; i++) { array[i, 0] = info[i].ip; array[i, 1] = info[i].port; array.SetData(i, 2, info[i].name); } fake.SetData(Req.Args, array); db.fakeStruct = fake; linker.Send(AES.Instance.Encrypt(db.ToBytes()), EnvelopeType.AesDataBuffer); } }
public void GetRoomDetail(KcpUser linker) { DataBuffer data = new DataBuffer(); var fake = new FakeStruct(data, Req.Length); fake[Req.Cmd] = RpcCmd.RoomDetail; fake[Req.Type] = MessageType.Rpc; FakeStructArray gs = new FakeStructArray(data, 3, 3); for (int i = 0; i < 3; i++) { var user = gamers[i].userInfo; if (user != null) { //gs[i, 0] = user.id; //gs[i, 1] = 1000;//金币 //gs[i, 2] = gamers[i].ready; } } fake.SetData(Req.Args, gs); data.fakeStruct = fake; linker.Send(AES.Instance.Encrypt(data.ToBytes()), EnvelopeType.AesDataBuffer); }