protected void deserializeEvent(StateObject state, int bytesRead) { //Receive message from the server formatter = new BinaryFormatter(); memStream = new MemoryStream(bytesRead - 1); memStream.Write(state.Buffer, 0, bytesRead - 1); memStream.Position = 0; UniVRPNity.Event event_deserialize = (UniVRPNity.Event)formatter.Deserialize(memStream); switch (event_deserialize.GetHandlerType()) { case UniVRPNity.Type.Analog: analogEvent = (AnalogEvent) event_deserialize; bufferEvent.Push(analogEvent); break; case UniVRPNity.Type.Button: buttonEvent = (ButtonEvent) event_deserialize; bufferEvent.Push(buttonEvent); break; case UniVRPNity.Type.Tracker: trackerEvent = (TrackerEvent) event_deserialize; bufferEvent.Push(trackerEvent); break; default: throw new Exception("Deserialization of the event failed.\n"); } }
private void Update(ButtonEvent e) { if (e.Button < buttonStates.Capacity) { buttonStates[e.Button] = e; } }
/* Button event handler */ private void ButtonChanged(object sender, ButtonChangeEventArgs e) { Vrpn.ButtonRemote buttonSender = (Vrpn.ButtonRemote) sender; if (this.remotes.isPresent(buttonSender)) { ButtonEvent buttonEvent = new ButtonEvent(this.remotes[buttonSender].Name); buttonEvent.Button = e.Button; buttonEvent.State = e.IsPressed; buttonEvent.Time = e.Time; Console.WriteLine("Button: " + buttonEvent); this.SendEvent(buttonSender, buttonEvent); } else { buttonSender.ButtonChanged -= new Vrpn.ButtonChangeEventHandler(this.ButtonChanged); } }