protected static byte[] SerializeExposedObject(ExposedObject input) { if (input == null) return null; ComposedByteStream stream = ComposedByteStream.FetchStream(); stream.AddStream(input.fieldName); stream.AddStream(input.typeName); stream.AddStream(new byte[] { (byte)(input.isStruct ? byte.MaxValue : byte.MinValue) }); stream.AddStream(SerializeSharedHelper.SerializeStrings(input.primitiveMembers)); stream.AddStream(ExposedObject.SerializeArray(input.objectMembers)); stream.AddStream(ExposedCollection.SerializeArray(input.collectionMembers)); stream.AddStream(ExposedUnityObjectPointer.SerializeArray(input.unityObjectMembers)); return stream.Compose(); }
private void DrawObjects(string id, ExposedObject[] objects, int depth, string customName = null) { if (objects == null || objects.Length == 0) return; GUILayout.BeginHorizontal(); GUILayout.Space(depth * depthSpacing); GUILayout.BeginVertical(); id += "_obj_"; for (int i = 0; i < objects.Length; i++) { ExposedObject obj = objects[i]; if (obj == null) continue; id += i; if (!inspectorFoldoutStates.ContainsKey(id)) inspectorFoldoutStates.Add(id, false); if (inspectorFoldoutStates[id] = EditorGUILayout.Foldout(inspectorFoldoutStates[id], customName != null ? customName : obj.fieldName, EditorHelper.styleHierarchyFoldout)) { if (obj.primitiveMembers != null && obj.primitiveMembers.Length > 0) { if (obj.isStruct) { DrawPrimitivesGrid(obj.primitiveMembers, 1); } else { DrawPrimitivesCollumn(obj.primitiveMembers, 1); } } if (obj.collectionMembers != null && obj.collectionMembers.Length > 0) { DrawCollections(id, obj.collectionMembers, 1); } if (obj.objectMembers != null && obj.objectMembers.Length > 0) { DrawObjects(id, obj.objectMembers, 1); } if (obj.unityObjectMembers != null && obj.unityObjectMembers.Length > 0) { DrawUnityObjectPointer(obj.unityObjectMembers, 1); } } } GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
protected static void DeserializeExposedObject(ref ComposedByteStream stream, ExposedObject storeTo) { storeTo.fieldName = stream.ReadNextStream(); storeTo.typeName = stream.ReadNextStream(); storeTo.isStruct = stream.ReadNextStream<byte>()[0] == byte.MaxValue; storeTo.primitiveMembers = SerializeSharedHelper.DeserializeStrings(stream.ReadNextStream<byte>()); storeTo.objectMembers = ExposedObject.DeserializeArray(stream.ReadNextStream<byte>()); storeTo.collectionMembers = ExposedCollection.Deserialize(stream.ReadNextStream<byte>()); storeTo.unityObjectMembers = ExposedUnityObjectPointer.DeserializeArray(stream.ReadNextStream<byte>()); }
//--------------- SERIALIZE -------------------- public static byte[] SerializeArray(ExposedObject[] input) { if (input == null) return null; ComposedByteStream stream = ComposedByteStream.FetchStream(); for (int i = 0; i < input.Length; i++) stream.AddStream(Serialize(input[i])); return stream.Compose(); }
public static byte[] Serialize(ExposedObject input) { if (input == null) return null; return SerializeExposedObject(input); }
//--------------- SERIALIZE -------------------- //--------------- DESERIALIZE -------------------- public static ExposedObject[] DeserializeArray(byte[] input) { if (input == null) return null; ComposedByteStream stream = ComposedByteStream.FromByteArray(input); if (stream == null) return null; int iMax = stream.streamCount; ExposedObject[] result = new ExposedObject[iMax]; for (int i = 0; i < iMax; i++) result[i] = Deserialize(stream.ReadNextStream<byte>()); stream.Dispose(); return result; }
public static ExposedObject Deserialize(byte[] input) { if (input == null) return null; ComposedByteStream stream = ComposedByteStream.FromByteArray(input); if (stream == null || stream.streamCount == 0) return null; ExposedObject result = new ExposedObject(); ExposedObject.DeserializeExposedObject(ref stream, result); stream.Dispose(); return result; }