| 1 |
using System; |
| 2 |
using System.Xml; |
| 3 |
using Oni.Metadata; |
| 4 |
using Oni.Xml; |
| 5 |
|
| 6 |
namespace Oni.Objects |
| 7 |
{ |
| 8 |
internal class Particle : ObjectBase |
| 9 |
{ |
| 10 |
public string ClassName; |
| 11 |
public string Tag; |
| 12 |
public ParticleFlags Flags; |
| 13 |
public Vector2 DecalScale = new Vector2(1.0f, 1.0f); |
| 14 |
|
| 15 |
public Particle() |
| 16 |
{ |
| 17 |
TypeId = ObjectType.Particle; |
| 18 |
} |
| 19 |
|
| 20 |
protected override void WriteOsd(BinaryWriter writer) |
| 21 |
{ |
| 22 |
writer.Write(ClassName, 64); |
| 23 |
writer.Write(Tag, 48); |
| 24 |
writer.Write((ushort)Flags); |
| 25 |
writer.Write(DecalScale); |
| 26 |
} |
| 27 |
|
| 28 |
protected override void ReadOsd(BinaryReader reader) |
| 29 |
{ |
| 30 |
ClassName = reader.ReadString(64); |
| 31 |
Tag = reader.ReadString(48); |
| 32 |
Flags = (ParticleFlags)reader.ReadUInt16(); |
| 33 |
DecalScale = reader.ReadVector2(); |
| 34 |
} |
| 35 |
|
| 36 |
protected override void WriteOsd(XmlWriter xml) |
| 37 |
{ |
| 38 |
xml.WriteElementString("Class", ClassName); |
| 39 |
xml.WriteElementString("Tag", Tag); |
| 40 |
xml.WriteElementString("Flags", MetaEnum.ToString<ParticleFlags>(Flags)); |
| 41 |
xml.WriteElementString("DecalScale", XmlConvert.ToString(DecalScale.X) + " " + XmlConvert.ToString(DecalScale.Y)); |
| 42 |
} |
| 43 |
|
| 44 |
protected override void ReadOsd(XmlReader xml, ObjectLoadContext context) |
| 45 |
{ |
| 46 |
while (xml.IsStartElement()) |
| 47 |
{ |
| 48 |
switch (xml.LocalName) |
| 49 |
{ |
| 50 |
case "Class": |
| 51 |
ClassName = xml.ReadElementContentAsString(); |
| 52 |
break; |
| 53 |
case "Tag": |
| 54 |
Tag = xml.ReadElementContentAsString(); |
| 55 |
break; |
| 56 |
case "Flags": |
| 57 |
Flags = xml.ReadElementContentAsEnum<ParticleFlags>() & ParticleFlags.NotInitiallyCreated; |
| 58 |
break; |
| 59 |
case "DecalScale": |
| 60 |
DecalScale = xml.ReadElementContentAsVector2(); |
| 61 |
break; |
| 62 |
default: |
| 63 |
xml.Skip(); |
| 64 |
break; |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
} |