public void Serialize(JObject root) { root["guid"] = this.internal_guid.ToString(); root["ref_guid"] = this.reference_guid.ToString(); root["position"] = this.position.Serialize(); root["rotation"] = this.m_rotation.Serialize(); root["segnum"] = this.m_segnum.ToString(); root["type"] = this.Type.ToString(); root["sub_type"] = SubTypeName(); // note: Use the string name of the enum so future enum changes are handled and sub_types don't mysteriously change root["mp_team"] = this.m_multiplayer_team_association_mask.ToString(); var e_props = new JObject(); var serializer = new EntityPropsSerializer(); serializer.Serialize(entity_props, e_props); root["properties"] = e_props; }
public void Deserialize(JObject root) { this.alive = true; this.marked = false; // Older versions of serialized Entity does not // have Guids defined. Detect those cases and // generate the Guid at deserialization var guid_type_obj = root["guid"]; if (guid_type_obj != null && guid_type_obj.Type == JTokenType.String) { this.internal_guid = guid_type_obj.GetGuid(Guid.Empty); } else { // Generate a Guid this.internal_guid = Guid.NewGuid(); } this.reference_guid = root["ref_guid"].GetGuid(Guid.Empty); this.m_position = root["position"].GetVector3(); this.m_rotation = root["rotation"].GetMatrix4(); this.m_segnum = root["segnum"].GetInt(-1); this.m_multiplayer_team_association_mask = root["mp_team"].GetInt(0); this.m_type = root["type"].GetEnum <EntityType>(EntityType.ENEMY); SetEntityProps(); var sub_type_obj = root["sub_type"]; if (sub_type_obj.Type == JTokenType.String) { this.SubType = GetSubTypeByName(sub_type_obj.GetString()); } else { this.SubType = sub_type_obj.GetInt(0); } var serializer = new EntityPropsSerializer(); serializer.Deserialize(entity_props, root["properties"].GetObject()); }