Skip to content

Commit f735c0f

Browse files
committed
Add possibility to make simple custom types that can be handled by the BitWriter/BitReader.
This opens up possibility to add simple custom types to the default NetworkedVar system and the simple version of rpc's.
1 parent 91e84f2 commit f735c0f

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitReader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ public object ReadObjectPacked(Type type)
127127
return ReadRotation(3);
128128
if (type == typeof(char))
129129
return ReadCharPacked();
130+
if (type == typeof(IBitWritable)) {
131+
object instance = Activator.CreateInstance(type);
132+
((IBitWritable)instance).Read(this);
133+
return instance;
134+
}
130135
throw new ArgumentException("BitReader cannot read type " + type.Name);
131136
}
132137

MLAPI/NetworkingManagerComponents/Binary/BitWriter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ public void WriteObjectPacked(object value)
145145
WriteCharPacked((char)value);
146146
return;
147147
}
148+
else if(value is IBitWritable)
149+
{
150+
((IBitWritable)value).Write(this);
151+
return;
152+
}
148153

149154
throw new ArgumentException("BitWriter cannot write type " + value.GetType().Name);
150155
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace MLAPI.Serialization {
7+
interface IBitWritable {
8+
void Write(BitWriter writer);
9+
void Read(BitReader reader);
10+
}
11+
}

0 commit comments

Comments
 (0)