/// <summary> /// reads flatbuffers byte data into object /// </summary> /// <param name="fbData"></param> public void Read(Byte[] fbData) { ByteBuffer byteBuffer = new ByteBuffer(fbData); m_FBData = XFBType.Scene.GetRootAsScene(byteBuffer); // read // XFBType.Colour colour = m_FBData.ColourAmbient; // m_ColourAmbient = System.Windows.Media.Color.FromScRgb(colour.A, colour.R, colour.G, colour.B); //ByteBuffer byteBuffer2 = new ByteBuffer(fbData); //var m_FBDataNOT = XFBType.Scene.GetRootAsScene(byteBuffer2); // read //XFBType.Colour colourNOT = m_FBDataNOT.ColourAmbient(); //m_ColourAmbient = System.Windows.Media.Color.FromScRgb(colourNOT.A(), colourNOT.R(), colourNOT.G(), colourNOT.B()); }
// This will be called whenever the list changes. private void ServerEvent(object sender, SampleEventArgs e) { Console.WriteLine("-> ServerEvent incoming Message"); // Verify the message contents are trustworthy. try { ByteBuffer byteBuffer = new ByteBuffer(e.Data); var message = NetMsg.MessageRoot.GetRootAsMessageRoot(byteBuffer); // read Console.WriteLine("-> ServerEvent incoming Message.DataType:" + message.DataType); switch (message.DataType) { case NetMsg.Data.ReturnStatus: NetMsg.ReturnStatus status = new NetMsg.ReturnStatus(); status = message.GetData <NetMsg.ReturnStatus>(status); switch (status.Status) { case NetMsg.MsgStatus.S_LoginSuccess: _SocketServerManager.Client.HostInfo.isLoggedIn = true; break; } break; case NetMsg.Data.Chatmessage: NetMsg.Chatmessage msg = new NetMsg.Chatmessage(); msg = message.GetData <NetMsg.Chatmessage>(msg); Console.WriteLine("NetMsg.Data.Chatmessage:" + msg.Text); break; case NetMsg.Data.Scene: XFBType.Scene scene = new XFBType.Scene(); scene = message.GetData <XFBType.Scene>(scene); Console.WriteLine("NetMsg.Data.Scene:" + scene.Sceneid); break; case NetMsg.Data.Entity: Entity ent = new Entity(); ent = message.GetData <Entity>(ent); Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Normal, new Action(() => { var model = this.DataContext as SocketServerToolModel; var entityExists = model.SceneItems.Where(x => x.Entity.EntityID == ent.EntityID); if (entityExists.Any()) { var existingEntity = entityExists.First(); for (int i = 0; i < ent.ComponentsLength; i++) { var comp = ent.GetComponents(i); Console.WriteLine("NetMsg.Data.Entity -> ComponentType:" + comp.CompType); if (comp.CompType == UComponent.BodyComponent) { XFBType.BodyComponent fbBody = new XFBType.BodyComponent(); comp.GetComp(fbBody); var body = existingEntity.Entity.GetComponentX <BodyComponent>() as BodyComponent; body.FB_BodyComponent.Location = new Interface.Scene.Services.Vector3() { X = fbBody.Position.X, Y = fbBody.Position.Y, Z = fbBody.Position.Z }; body.FB_BodyComponent.Rotation = new Interface.Scene.Services.Quaternion() { W = fbBody.Rotation.W, X = fbBody.Rotation.X, Y = fbBody.Rotation.Y, Z = fbBody.Rotation.Z }; body.FB_BodyComponent.Scale = new Interface.Scene.Services.Vector3() { X = fbBody.Scale.X, Y = fbBody.Scale.Y, Z = fbBody.Scale.Z }; } } } else // new entity { var newEntity = new EntityX() { EntityID = ent.EntityID, NetID = message.Netid, SceneID = message.Scene }; for (int i = 0; i < ent.ComponentsLength; i++) { var comp = ent.GetComponents(i); Console.WriteLine("NetMsg.Data.Entity -> ComponentType:" + comp.CompType); if (comp.CompType == UComponent.BodyComponent) { XFBType.BodyComponent fbBody = new XFBType.BodyComponent(); comp.GetComp(fbBody); var body = new BodyComponent() { Parent = newEntity }; body.FB_BodyComponent.Location = new Interface.Scene.Services.Vector3() { X = fbBody.Position.X, Y = fbBody.Position.Y, Z = fbBody.Position.Z }; body.FB_BodyComponent.Rotation = new Interface.Scene.Services.Quaternion() { W = fbBody.Rotation.W, X = fbBody.Rotation.X, Y = fbBody.Rotation.Y, Z = fbBody.Rotation.Z }; body.FB_BodyComponent.Scale = new Interface.Scene.Services.Vector3() { X = fbBody.Scale.X, Y = fbBody.Scale.Y, Z = fbBody.Scale.Z }; newEntity.Components.Add(body); } } model.SceneItems.Add(new SourceItem() { Entity = newEntity }); } })); break; } } catch (Exception ex) { Console.WriteLine(e.Data); } }