| 1 |
using System; |
| 2 |
using System.Xml; |
| 3 |
using Oni.Xml; |
| 4 |
|
| 5 |
namespace Oni.Objects |
| 6 |
{ |
| 7 |
internal class Sound : ObjectBase |
| 8 |
{ |
| 9 |
public string ClassName; |
| 10 |
public float Volume = 1.0f; |
| 11 |
public float Pitch = 1.0f; |
| 12 |
public SoundVolumeType Type; |
| 13 |
public BoundingBox Box; |
| 14 |
public float MinDistance; |
| 15 |
public float MaxDistance; |
| 16 |
|
| 17 |
public Sound() |
| 18 |
{ |
| 19 |
TypeId = ObjectType.Sound; |
| 20 |
} |
| 21 |
|
| 22 |
protected override void WriteOsd(BinaryWriter writer) |
| 23 |
{ |
| 24 |
writer.Write(ClassName, 32); |
| 25 |
writer.Write((uint)Type); |
| 26 |
|
| 27 |
if (Type == SoundVolumeType.Box) |
| 28 |
{ |
| 29 |
writer.Write(Box); |
| 30 |
} |
| 31 |
else |
| 32 |
{ |
| 33 |
writer.Write(MinDistance); |
| 34 |
writer.Write(MaxDistance); |
| 35 |
} |
| 36 |
|
| 37 |
writer.Write(Volume); |
| 38 |
writer.Write(Pitch); |
| 39 |
} |
| 40 |
|
| 41 |
protected override void ReadOsd(BinaryReader reader) |
| 42 |
{ |
| 43 |
ClassName = reader.ReadString(32); |
| 44 |
Type = (SoundVolumeType)reader.ReadInt32(); |
| 45 |
|
| 46 |
if (Type == SoundVolumeType.Box) |
| 47 |
{ |
| 48 |
Box = reader.ReadBoundingBox(); |
| 49 |
} |
| 50 |
else if (Type == SoundVolumeType.Sphere) |
| 51 |
{ |
| 52 |
MinDistance = reader.ReadSingle(); |
| 53 |
MaxDistance = reader.ReadSingle(); |
| 54 |
} |
| 55 |
|
| 56 |
Volume = reader.ReadSingle(); |
| 57 |
Pitch = reader.ReadSingle(); |
| 58 |
} |
| 59 |
|
| 60 |
protected override void ReadOsd(XmlReader xml, ObjectLoadContext context) |
| 61 |
{ |
| 62 |
ClassName = xml.ReadElementContentAsString("Class", ""); |
| 63 |
|
| 64 |
if (xml.IsStartElement("Volume")) |
| 65 |
{ |
| 66 |
Volume = xml.ReadElementContentAsFloat("Volume", ""); |
| 67 |
Pitch = xml.ReadElementContentAsFloat("Pitch", ""); |
| 68 |
|
| 69 |
if (xml.IsStartElement("Box", "")) |
| 70 |
{ |
| 71 |
Type = SoundVolumeType.Box; |
| 72 |
xml.ReadStartElement(); |
| 73 |
Box.Min = xml.ReadElementContentAsVector3("Min"); |
| 74 |
Box.Max = xml.ReadElementContentAsVector3("Max"); |
| 75 |
xml.ReadEndElement(); |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
Type = SoundVolumeType.Sphere; |
| 80 |
xml.ReadStartElement("Spheres"); |
| 81 |
MinDistance = xml.ReadElementContentAsFloat("Min", ""); |
| 82 |
MaxDistance = xml.ReadElementContentAsFloat("Max", ""); |
| 83 |
xml.ReadEndElement(); |
| 84 |
} |
| 85 |
} |
| 86 |
else |
| 87 |
{ |
| 88 |
if (xml.IsStartElement("Box", "")) |
| 89 |
{ |
| 90 |
Type = SoundVolumeType.Box; |
| 91 |
xml.ReadStartElement(); |
| 92 |
Box.Min = xml.ReadElementContentAsVector3("Min"); |
| 93 |
Box.Max = xml.ReadElementContentAsVector3("Max"); |
| 94 |
xml.ReadEndElement(); |
| 95 |
} |
| 96 |
else |
| 97 |
{ |
| 98 |
Type = SoundVolumeType.Sphere; |
| 99 |
xml.ReadStartElement("Sphere"); |
| 100 |
MinDistance = xml.ReadElementContentAsFloat("MinRadius", ""); |
| 101 |
MaxDistance = xml.ReadElementContentAsFloat("MaxRadius", ""); |
| 102 |
xml.ReadEndElement(); |
| 103 |
} |
| 104 |
|
| 105 |
Volume = xml.ReadElementContentAsFloat("Volume", ""); |
| 106 |
Pitch = xml.ReadElementContentAsFloat("Pitch", ""); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
protected override void WriteOsd(XmlWriter xml) |
| 111 |
{ |
| 112 |
throw new NotImplementedException(); |
| 113 |
} |
| 114 |
} |
| 115 |
} |