public override byte[] GetMessageBytes() { int msgLen = GetBaseSize() + sizeof(int) + menuList.Count; // BaseSize + list entries (int) + 1 byte for each string length ... foreach (string str in menuList) { msgLen += str.Length; // ... + 1 byte for each character in each string. } _bytes = new byte[msgLen]; int index = 0; PackDuties(ref index); // Msg Type MobileControlPackHelper.PackInt(ref _bytes, ref index, menuList.Count); // Amount of list entries // For each list entry: for (int ii = 0; ii < menuList.Count; ++ii) { MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(menuList[ii].Length)); // Amound of letters for this element MobileControlPackHelper.PackString(ref _bytes, ref index, menuList[ii]); // list entry (letter for letter, not null terminated) } return(_bytes); }
public override byte[] GetMessageBytes() { int msgLen = GetBaseSize() + 1 + disabledButtonList.Count + 1 + namedButtonList.Count; // BaseSize + 1 amount of optional bytes + optional bytes (disabled and named amount) // + 1 amount of named buttons + amount of strings. foreach (KeyValuePair <uint, string> entry in namedButtonList) { msgLen += entry.Value.Length + 1; // ... + x bytes (for all characters of each "named button" string) + 1 byte (for amount of chars). } _bytes = new byte[msgLen]; int index = 0; PackDuties(ref index); // Msg Type MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(disabledButtonList.Count)); // Amount of optional disabled button bytes foreach (uint disabledOption in disabledButtonList) { MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(disabledOption)); // For each disabled button, add the button id. } MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(namedButtonList.Count)); // Amount of optional named buttons foreach (KeyValuePair <uint, string> entry in namedButtonList) { MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(entry.Key)); // For each named button, add the button id. MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(entry.Value.Length)); // Amound of letters for this element MobileControlPackHelper.PackString(ref _bytes, ref index, entry.Value); // And afterwards the string (button name). } return(_bytes); }
public override byte[] GetMessageBytes() { int msgLen = GetBaseSize() + 1 + sliders.Count * 3 * sizeof(float) + sliders.Count; // BaseSize + Amount of Sliders + <AmountOfSlider> * 3 * float + 1 Byte for each string (string amount before str) foreach (SliderDetails sd in sliders) { msgLen += sd.name.Length; // ... + 1 byte for each character in each string. } _bytes = new byte[msgLen]; int index = 0; PackDuties(ref index); // Msg Type MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(sliders.Count)); // Amount of sliders foreach (SliderDetails sd in sliders) // For each slider: { MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(sd.name.Length)); // Amound of letters for this name MobileControlPackHelper.PackString(ref _bytes, ref index, sd.name); // name (letter for letter, not null terminated) MobileControlPackHelper.PackFloat(ref _bytes, ref index, sd.minValue); // Minimum Slider Value MobileControlPackHelper.PackFloat(ref _bytes, ref index, sd.maxValue); // Maximum Slider Value MobileControlPackHelper.PackFloat(ref _bytes, ref index, sd.curValue); // Current Slider Value } return(_bytes); }
public override int UnpackReceivedMessage() { int index = 0; UnpackDuties(ref index); // Message Type chosenIndex = MobileControlPackHelper.UnpackInt(_bytes, ref index); // Index of the chosen list entry. return(index); }
public override int UnpackReceivedMessage() { int index = 0; UnpackDuties(ref index); // Message Type _chosenOption = MobileControlPackHelper.UnpackByte(_bytes, ref index); // chosenOption return(index); }
public override int UnpackReceivedMessage() { int index = 0; UnpackDuties(ref index); // Message Type _windowNumber = MobileControlPackHelper.UnpackByte(_bytes, ref index); // Window number return(index); }
public override int UnpackReceivedMessage() { int index = 0; UnpackDuties(ref index); // Message Type _categoryID = MobileControlPackHelper.UnpackByte(_bytes, ref index); // ID of the category (microstory) _sectionID = MobileControlPackHelper.UnpackByte(_bytes, ref index); // ID of the scene (Microstory-Part) return(index); }
public override int UnpackReceivedMessage() { int index = 0; UnpackDuties(ref index); // Message Type sliderIndex = Convert.ToInt32(MobileControlPackHelper.UnpackByte(_bytes, ref index)); // Index of the changed slider curSliderValue = MobileControlPackHelper.UnpackFloat(_bytes, ref index); // Current Slider Value return(index); }
protected void UnpackDuties(ref int index) { Command cmd = (Command)MobileControlPackHelper.UnpackByte(_bytes, ref index); // Message Type //_netID = MobileControlPackHelper.UnpackUint(bytes, ref index); // Network ID if (cmd != Command) { Debug.LogError("Received Command is not the expected one!\n" + "Expected: " + Enum.GetName(typeof(Command), _command) + ", Received: " + Enum.GetName(typeof(Command), cmd)); } }
public override byte[] GetMessageBytes() { int msgLen = GetBaseSize(); // Figure out size of the data: msgLen += 1; // Amount of Categories for (int categoryIndex = 0; categoryIndex < categorySectionList.Count; ++categoryIndex) { Category category = categorySectionList[categoryIndex]; msgLen += 1 + 1 + category.categoryName.Length + 1; // Category ID + Amount of Chars (Category Name) + Category Name + Amount of Scenes for (int sceneIndex = 0; sceneIndex < category.sectionList.Count; ++sceneIndex) { Category.Section section = category.sectionList[sceneIndex]; msgLen += 1 + 1 + section.sectionName.Length; // Scene ID + Amount of Chars (Category Name) + Scene Name } } // Now start packing: _bytes = new byte[msgLen]; int index = 0; PackDuties(ref index); // Msg Type MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(categorySectionList.Count)); // Amount of Categories for (int categoryIndex = 0; categoryIndex < categorySectionList.Count; ++categoryIndex) { Category category = categorySectionList[categoryIndex]; MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(category.categoryID)); // Category ID MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(category.categoryName.Length)); // Category Name String Length MobileControlPackHelper.PackString(ref _bytes, ref index, category.categoryName); // Category Name MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(category.sectionList.Count)); // Amount of Scenes for (int sceneIndex = 0; sceneIndex < category.sectionList.Count; ++sceneIndex) { Category.Section section = category.sectionList[sceneIndex]; MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(section.sectionID)); // Scene ID MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(section.sectionName.Length)); // Section Name String Length MobileControlPackHelper.PackString(ref _bytes, ref index, section.sectionName); // Section Name } } return(_bytes); }
public override byte[] GetMessageBytes() { int msgLen = GetBaseSize() + 1; // BaseSize + 1 byte (state) _bytes = new byte[msgLen]; int index = 0; PackDuties(ref index); // Msg Type MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(quizButton)); // quizButton State return(_bytes); }
public override byte[] GetMessageBytes() { int msgLen = GetBaseSize() + sizeof(byte); // BaseSize + current play state _bytes = new byte[msgLen]; int index = 0; PackDuties(ref index); // Msg Type MobileControlPackHelper.PackByte(ref _bytes, ref index, Convert.ToByte(videoIsPaused)); return(_bytes); }
public override byte[] GetMessageBytes() { int msgLen = GetBaseSize() + 1 + 1; // BaseSize + CategoryID + SectionID _bytes = new byte[msgLen]; int index = 0; PackDuties(ref index); // Msg Type MobileControlPackHelper.PackByte(ref _bytes, ref index, _categoryID); MobileControlPackHelper.PackByte(ref _bytes, ref index, _sectionID); return(_bytes); }
public static Command ReadMessageCommand(byte[] bytes) { int index = 0; // 0 -> Command Byte. Command command = Command.UNKNOWN; try { command = (Command)MobileControlPackHelper.UnpackByte(bytes, ref index); // Message Type } catch (System.Exception) { command = Command.UNKNOWN; } return(command); }
public override int UnpackReceivedMessage() { int index = 0; UnpackDuties(ref index); // Message Type int fingerAmount = Convert.ToInt32(MobileControlPackHelper.UnpackByte(_bytes, ref index)); // Amount of fingers on the touch display fingerPositions = new List <FingerPosition>(fingerAmount); for (int ii = 0; ii < fingerAmount; ++ii) { FingerPosition fingerPos = new FingerPosition(); fingerPos.fingerID = Convert.ToInt32(MobileControlPackHelper.UnpackByte(_bytes, ref index)); // Current Finger ID fingerPos.xPos = MobileControlPackHelper.UnpackFloat(_bytes, ref index); // Current Finger xPos fingerPos.yPos = MobileControlPackHelper.UnpackFloat(_bytes, ref index); // Current Finger yPos fingerPositions.Add(fingerPos); } return(index); }
protected void PackDuties(ref int index) { MobileControlPackHelper.PackByte(ref _bytes, ref index, ByteCommand); // Message Type (1) //MobileControlPackHelper.PackUint(ref message, ref index, NetworkID); // Network ID (4) }