Skip to content

Commit b8505f9

Browse files
committed
fixes detecting inherited Schema types inside ArraySchema/MapSchema
1 parent bc717d1 commit b8505f9

File tree

1 file changed

+20
-2
lines changed
  • Assets/Plugins/Colyseus/Serializer/Schema

1 file changed

+20
-2
lines changed

Assets/Plugins/Colyseus/Serializer/Schema/Schema.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public class ArraySchema<T> : ISchemaCollection
122122
public event KeyValueEventHandler<T, int> OnAdd;
123123
public event KeyValueEventHandler<T, int> OnChange;
124124
public event KeyValueEventHandler<T, int> OnRemove;
125+
private bool _hasSchemaChild = Schema.CheckSchemaChild(typeof(T));
125126

126127
public ArraySchema()
127128
{
@@ -156,7 +157,7 @@ public bool ContainsKey(object key)
156157

157158
public bool HasSchemaChild
158159
{
159-
get { return typeof(T).BaseType == typeof(Schema); }
160+
get { return _hasSchemaChild; }
160161
}
161162

162163
public int Count
@@ -232,6 +233,7 @@ public class MapSchema<T> : ISchemaCollection
232233
public event KeyValueEventHandler<T, string> OnAdd;
233234
public event KeyValueEventHandler<T, string> OnChange;
234235
public event KeyValueEventHandler<T, string> OnRemove;
236+
private bool _hasSchemaChild = Schema.CheckSchemaChild(typeof(T));
235237

236238
public MapSchema()
237239
{
@@ -266,7 +268,7 @@ public bool ContainsKey(object key)
266268

267269
public bool HasSchemaChild
268270
{
269-
get { return typeof(T).BaseType == typeof(Schema); }
271+
get { return _hasSchemaChild; }
270272
}
271273

272274
public T this[string key]
@@ -760,6 +762,22 @@ protected object CreateTypeInstance(byte[] bytes, Iterator it, System.Type type)
760762
return Activator.CreateInstance(type);
761763
}
762764
}
765+
766+
public static bool CheckSchemaChild(System.Type toCheck) {
767+
System.Type generic = typeof(Schema);
768+
769+
while (toCheck != null && toCheck != typeof(object)) {
770+
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
771+
772+
if (generic == cur) {
773+
return true;
774+
}
775+
776+
toCheck = toCheck.BaseType;
777+
}
778+
779+
return false;
780+
}
763781
}
764782

765783
public class ReflectionField : Schema

0 commit comments

Comments
 (0)