private static OSCBundle UnpackBundle(byte[] bytes, ref int start, int end) { OSCBundle bundle = null; var address = (string)UnpackValue(OSCValueType.String, bytes, ref start); if (address.Equals(OSCBundle.BundleAddress)) { var timeStamp = (long)UnpackValue(OSCValueType.Long, bytes, ref start); bundle = new OSCBundle(); bundle.TimeStamp = timeStamp; while (start < end) { var packetLength = (int)UnpackValue(OSCValueType.Int, bytes, ref start); var packet = UnpackInternal(bytes, ref start, start + packetLength); bundle.AddPacket(packet); } } return(bundle); }
private static void DrawEditableBundle(OSCBundle bundle) { var defaultColor = GUI.color; if (bundle.Packets.Count > 0) { OSCPacket removePacket = null; foreach (var bundlePacket in bundle.Packets) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(bundlePacket.GetType().Name + ":", EditorStyles.boldLabel); GUI.color = Color.red; var deleteButton = GUILayout.Button("x", GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.Width(20)); if (deleteButton) { removePacket = bundlePacket; } GUI.color = defaultColor; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical("box"); EditablePacket(bundlePacket); EditorGUILayout.EndVertical(); GUILayout.Space(10); } if (removePacket != null) { bundle.Packets.Remove(removePacket); if (_valueTypeTemp.ContainsKey(removePacket)) { _valueTypeTemp.Remove(removePacket); } } } else { EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField(_bundleEmptyContent, OSCEditorStyles.CenterLabel); EditorGUILayout.EndVertical(); } // ADD PACKET EditorGUILayout.BeginHorizontal("box"); GUI.color = Color.green; if (GUILayout.Button(_addBundleContent)) { bundle.AddPacket(new OSCBundle()); } if (GUILayout.Button(_addMessageContent)) { bundle.AddPacket(new OSCMessage("/address")); } GUI.color = defaultColor; EditorGUILayout.EndHorizontal(); }
private void DrawBundle(OSCBundle bundle) { var defaultColor = GUI.color; if (bundle.Packets.Count > 0) { var removePacket = (IOSCPacket)null; foreach (var bundlePacket in bundle.Packets) { using (new GUILayout.HorizontalScope()) { EditorGUILayout.LabelField($"{bundlePacket.GetType().Name}:", EditorStyles.boldLabel); GUI.color = Color.red; if (GUILayout.Button(_closeContent, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.Width(EditorGUIUtility.singleLineHeight))) { removePacket = bundlePacket; } GUI.color = defaultColor; } using (new GUILayout.VerticalScope(OSCEditorStyles.Box)) { DrawLayout(bundlePacket); } GUILayout.Space(10); } if (removePacket != null) { bundle.Packets.Remove(removePacket); if (_valueTypeTemp.ContainsKey(removePacket)) { _valueTypeTemp.Remove(removePacket); } } } else { using (new GUILayout.VerticalScope(OSCEditorStyles.Box)) { EditorGUILayout.LabelField(_bundleEmptyContent, OSCEditorStyles.CenterLabel); } } // ADD PACKET using (new GUILayout.HorizontalScope(OSCEditorStyles.Box)) { GUI.color = Color.green; if (GUILayout.Button(_addBundleContent)) { bundle.AddPacket(new OSCBundle()); } if (GUILayout.Button(_addMessageContent)) { bundle.AddPacket(new OSCMessage("/address")); } GUI.color = defaultColor; } }