diff --git a/LibBSP/Source/Structs/Common/Entity.cs b/LibBSP/Source/Structs/Common/Entity.cs
index b38198c..bc033f4 100644
--- a/LibBSP/Source/Structs/Common/Entity.cs
+++ b/LibBSP/Source/Structs/Common/Entity.cs
@@ -6,6 +6,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
+using System.Runtime.Serialization;
#if UNITY
using UnityEngine;
#endif
@@ -18,7 +19,7 @@ namespace LibBSP {
///
/// Class containing all data for a single , including attributes, Source Entity I/O connections and solids.
///
- [Serializable] public class Entity : Dictionary, IComparable, IComparable {
+ [Serializable] public class Entity : Dictionary, IComparable, IComparable, ISerializable {
public const char ConnectionMemberSeparater = (char)0x1B;
@@ -142,7 +143,7 @@ namespace LibBSP {
if (ContainsKey(key)) {
return base[key];
} else {
- return string.Empty;
+ return "";
}
}
set { base[key] = value; }
@@ -248,6 +249,16 @@ namespace LibBSP {
}
}
+ ///
+ /// Initializes a new instance of the class with serialized data.
+ ///
+ /// A SerializationInfo object containing the information required to serialize the .
+ /// A StreamingContext structure containing the source and destination of the serialized stream associated with the .
+ protected Entity(SerializationInfo info, StreamingContext context) : base(info, context) {
+ connections = (List)info.GetValue("connections", typeof(List));
+ brushes = (List)info.GetValue("brushes", typeof(List));
+ }
+
///
/// Factory method to create an from a string "" where
/// "" contains all lines for the entity, including attributes, brushes, etc.
@@ -457,6 +468,7 @@ namespace LibBSP {
return new Vector4(results[0], results[1], results[2], results[3]);
}
+ #region IComparable
///
/// Compares this to another object. First "classname" attributes are compared, then "targetname".
/// Attributes are compared alphabetically. Targetnames are only compared if classnames match.
@@ -484,6 +496,22 @@ namespace LibBSP {
int firstTry = className.CompareTo(other.className);
return firstTry != 0 ? firstTry : name.CompareTo(other.name);
}
+ #endregion
+
+ #region ISerializable
+ ///
+ /// Implements the ISerializable interface and returns the data needed
+ /// to serialize the instance.
+ ///
+ /// A SerializationInfo object that contains the information required to serialize the instance.
+ /// A StreamingContext structure that contains the source and destination of the serialized stream associated with the instance.
+ public override void GetObjectData(SerializationInfo info, StreamingContext context) {
+ base.GetObjectData(info, context);
+ info.AddValue("connections", connections, typeof(List));
+ info.AddValue("brushes", brushes, typeof(List));
+
+ }
+ #endregion
///
/// Factory method for an object from a byte array.
@@ -549,7 +577,7 @@ namespace LibBSP {
///
/// Struct containing the fields necessary for Source entity I/O.
///
- public struct EntityConnection {
+ [Serializable] public struct EntityConnection {
public string name;
public string target;
public string action;
diff --git a/LibBSP/Source/Structs/Common/Lumps/Entities.cs b/LibBSP/Source/Structs/Common/Lumps/Entities.cs
index f4a7676..859b2f3 100644
--- a/LibBSP/Source/Structs/Common/Lumps/Entities.cs
+++ b/LibBSP/Source/Structs/Common/Lumps/Entities.cs
@@ -5,7 +5,7 @@ namespace LibBSP {
///
/// Class representing a group of objects. Contains helpful methods to handle Entities in the List.
///
- public class Entities : List {
+ [Serializable] public class Entities : List {
///
/// Initializes a new instance of an object copying a passed IEnumerable of objects.
diff --git a/LibBSP/Source/Structs/MAP/MAPBrush.cs b/LibBSP/Source/Structs/MAP/MAPBrush.cs
index b8c4ae2..d0f0931 100644
--- a/LibBSP/Source/Structs/MAP/MAPBrush.cs
+++ b/LibBSP/Source/Structs/MAP/MAPBrush.cs
@@ -2,13 +2,14 @@
#define UNITY
#endif
+using System;
using System.Collections.Generic;
namespace LibBSP {
///
/// Class containing all data for a single brush, including side definitions or a patch definition.
///
- public class MAPBrush {
+ [Serializable] public class MAPBrush {
public List sides = new List(6);
public MAPPatch patch;
diff --git a/LibBSP/Source/Structs/MAP/MAPBrushSide.cs b/LibBSP/Source/Structs/MAP/MAPBrushSide.cs
index 45606ae..0cf86bf 100644
--- a/LibBSP/Source/Structs/MAP/MAPBrushSide.cs
+++ b/LibBSP/Source/Structs/MAP/MAPBrushSide.cs
@@ -15,7 +15,7 @@ namespace LibBSP {
///
/// Class containing data for a brush side. Please note vertices must be set manually or generated through CSG.
///
- public class MAPBrushSide {
+ [Serializable] public class MAPBrushSide {
public Vector3[] vertices;
public Plane plane;
diff --git a/LibBSP/Source/Structs/MAP/MAPDisplacement.cs b/LibBSP/Source/Structs/MAP/MAPDisplacement.cs
index 0ccc933..53750b0 100644
--- a/LibBSP/Source/Structs/MAP/MAPDisplacement.cs
+++ b/LibBSP/Source/Structs/MAP/MAPDisplacement.cs
@@ -16,7 +16,7 @@ namespace LibBSP {
///
/// Class containing all data necessary to render a displacement from Source engine.
///
- public class MAPDisplacement {
+ [Serializable] public class MAPDisplacement {
public int power;
public Vector3 start;
diff --git a/LibBSP/Source/Structs/MAP/MAPPatch.cs b/LibBSP/Source/Structs/MAP/MAPPatch.cs
index 6cf280b..a8697fc 100644
--- a/LibBSP/Source/Structs/MAP/MAPPatch.cs
+++ b/LibBSP/Source/Structs/MAP/MAPPatch.cs
@@ -18,7 +18,7 @@ namespace LibBSP {
///
/// Class containing all data necessary to render a Bezier patch.
///
- public class MAPPatch {
+ [Serializable] public class MAPPatch {
public UIVertex[] points;
public Vector2 dims;