source: OniSplit/Particles/ImpactEffectParticle.cs@ 1114

Last change on this file since 1114 was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File size: 3.6 KB
RevLine 
[1114]1using System;
2using System.Collections.Generic;
3using System.Xml;
4
5namespace Oni.Particles
6{
7 internal class ImpactEffectParticle
8 {
9 #region Private data
10 private string particleClassName;
11 private int orientation;
12 private int location;
13 private float offset;
14 private bool decal1;
15 private bool decal2;
16 #endregion
17
18 public ImpactEffectParticle(BinaryReader reader)
19 {
20 particleClassName = reader.ReadString(64);
21 reader.Skip(4);
22 orientation = reader.ReadInt32();
23 location = reader.ReadInt32();
24
25 switch (location)
26 {
27 case 1:
28 offset = reader.ReadSingle();
29 reader.Skip(4);
30 break;
31 case 4:
32 decal1 = (reader.ReadByte() != 0);
33 decal2 = (reader.ReadByte() != 0);
34 reader.Skip(6);
35 break;
36 default:
37 reader.Skip(8);
38 break;
39 }
40 }
41
42 public void Write(BinaryWriter writer)
43 {
44 writer.Write(particleClassName, 64);
45 writer.Skip(4);
46 writer.Write(orientation);
47 writer.Write(location);
48
49 switch (location)
50 {
51 case 1:
52 writer.Write(offset);
53 break;
54
55 case 4:
56 writer.WriteByte(decal1 ? 1 : 0);
57 writer.WriteByte(decal2 ? 1 : 0);
58 writer.WriteUInt16(0);
59 break;
60
61 default:
62 writer.Write(0);
63 break;
64 }
65
66 writer.Write(0);
67 }
68
69 public ImpactEffectParticle(XmlReader xml)
70 {
71 particleClassName = xml.ReadElementContentAsString("Name", "");
72 orientation = XmlConvert.ToInt32(xml.ReadElementContentAsString("Orientation", ""));
73 location = XmlConvert.ToInt32(xml.ReadElementContentAsString("Location", ""));
74
75 switch (location)
76 {
77 case 1:
78 offset = XmlConvert.ToSingle(xml.ReadElementContentAsString("Offset", ""));
79 break;
80 case 4:
81 decal1 = bool.Parse(xml.ReadElementContentAsString("Decal1", ""));
82 decal2 = bool.Parse(xml.ReadElementContentAsString("Decal2", ""));
83 break;
84 }
85 }
86
87 public void Write(XmlWriter writer)
88 {
89 writer.WriteElementString("Name", particleClassName);
90 writer.WriteElementString("Orientation", XmlConvert.ToString(orientation));
91 writer.WriteElementString("Location", XmlConvert.ToString(location));
92
93 switch (location)
94 {
95 case 1:
96 writer.WriteElementString("Offset", XmlConvert.ToString(offset));
97 break;
98 case 4:
99 writer.WriteElementString("Decal1", XmlConvert.ToString(decal1));
100 writer.WriteElementString("Decal2", XmlConvert.ToString(decal2));
101 break;
102 }
103 }
104
105 public string ParticleClassName => particleClassName;
106
107 public int Orientation => orientation;
108 public int Location => location;
109 public float Offset => offset;
110
111 public bool Decal1 => decal1;
112 public bool Decal2 => decal2;
113 }
114}
Note: See TracBrowser for help on using the repository browser.