Skip to content

Commit e8d58d2

Browse files
committed
Cleaned up SyncedVar system slightly
1 parent 36e8c79 commit e8d58d2

File tree

2 files changed

+61
-291
lines changed

2 files changed

+61
-291
lines changed

MLAPI/Data/FieldType.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace MLAPI.Data
1+
using System;
2+
using UnityEngine;
3+
4+
namespace MLAPI.Data
25
{
36
/// <summary>
47
/// The datatype used to classify SyncedVars
@@ -20,6 +23,48 @@ internal enum FieldType
2023
Vector3,
2124
Vector2,
2225
Quaternion,
23-
ByteArray
26+
ByteArray,
27+
Invalid
28+
}
29+
30+
internal static class FieldTypeHelper
31+
{
32+
internal static FieldType GetFieldType(Type type)
33+
{
34+
if (type == typeof(bool))
35+
return FieldType.Bool;
36+
else if (type == typeof(byte))
37+
return FieldType.Byte;
38+
else if (type == typeof(double))
39+
return FieldType.Double;
40+
else if (type == typeof(float))
41+
return FieldType.Single;
42+
else if (type == typeof(int))
43+
return FieldType.Int;
44+
else if (type == typeof(long))
45+
return FieldType.Long;
46+
else if (type == typeof(sbyte))
47+
return FieldType.SByte;
48+
else if (type == typeof(short))
49+
return FieldType.Short;
50+
else if (type == typeof(uint))
51+
return FieldType.UInt;
52+
else if (type == typeof(ulong))
53+
return FieldType.ULong;
54+
else if (type == typeof(ushort))
55+
return FieldType.UShort;
56+
else if (type == typeof(string))
57+
return FieldType.String;
58+
else if (type == typeof(Vector3))
59+
return FieldType.Vector3;
60+
else if (type == typeof(Vector2))
61+
return FieldType.Vector2;
62+
else if (type == typeof(Quaternion))
63+
return FieldType.Quaternion;
64+
else if (type == typeof(byte[]))
65+
return FieldType.ByteArray;
66+
else
67+
return FieldType.Invalid;
68+
}
2469
}
2570
}

0 commit comments

Comments
 (0)