Skip to content

Commit 075820e

Browse files
committed
Added serializable versions of NetworkedVar
1 parent 721ce3b commit 075820e

2 files changed

Lines changed: 72 additions & 23 deletions

File tree

MLAPI-Editor/NetworkedBehaviourEditor.cs

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,41 @@ void RenderNetworkedVarValueType<T>(int index) where T : struct
9090
Type type = typeof(T);
9191
object val = var.Value;
9292
string name = networkedVarNames[index];
93-
if (type == typeof(int))
94-
val = EditorGUILayout.IntField(name, (int)val);
95-
else if (type == typeof(uint))
96-
val = (uint)EditorGUILayout.LongField(name, (long)((uint)val));
97-
else if (type == typeof(short))
98-
val = (short)EditorGUILayout.IntField(name, (int)((short)val));
99-
else if (type == typeof(ushort))
100-
val = (ushort)EditorGUILayout.IntField(name, (int)((ushort)val));
101-
else if (type == typeof(sbyte))
102-
val = (sbyte)EditorGUILayout.IntField(name, (int)((sbyte)val));
103-
else if (type == typeof(byte))
104-
val = (byte)EditorGUILayout.IntField(name, (int)((byte)val));
105-
else if (type == typeof(long))
106-
val = EditorGUILayout.LongField(name, (long)val);
107-
else if (type == typeof(ulong))
108-
val = (ulong)EditorGUILayout.LongField(name, (long)((ulong)val));
109-
else if (type == typeof(bool))
110-
val = EditorGUILayout.Toggle(name, (bool)val);
111-
else if (type == typeof(string))
112-
val = EditorGUILayout.TextField(name, (string)val);
113-
else
114-
EditorGUILayout.LabelField("Type not renderable");
11593

116-
var.Value = (T)val;
94+
if (NetworkingManager.singleton != null && NetworkingManager.singleton.isListening)
95+
{
96+
if (type == typeof(int))
97+
val = EditorGUILayout.IntField(name, (int)val);
98+
else if (type == typeof(uint))
99+
val = (uint)EditorGUILayout.LongField(name, (long)((uint)val));
100+
else if (type == typeof(short))
101+
val = (short)EditorGUILayout.IntField(name, (int)((short)val));
102+
else if (type == typeof(ushort))
103+
val = (ushort)EditorGUILayout.IntField(name, (int)((ushort)val));
104+
else if (type == typeof(sbyte))
105+
val = (sbyte)EditorGUILayout.IntField(name, (int)((sbyte)val));
106+
else if (type == typeof(byte))
107+
val = (byte)EditorGUILayout.IntField(name, (int)((byte)val));
108+
else if (type == typeof(long))
109+
val = EditorGUILayout.LongField(name, (long)val);
110+
else if (type == typeof(ulong))
111+
val = (ulong)EditorGUILayout.LongField(name, (long)((ulong)val));
112+
else if (type == typeof(bool))
113+
val = EditorGUILayout.Toggle(name, (bool)val);
114+
else if (type == typeof(string))
115+
val = EditorGUILayout.TextField(name, (string)val);
116+
else if (type.IsEnum)
117+
val = EditorGUILayout.EnumPopup(name, (Enum) val);
118+
else
119+
EditorGUILayout.LabelField("Type not renderable");
120+
121+
var.Value = (T)val;
122+
}
123+
else
124+
{
125+
EditorGUILayout.LabelField(name, EditorStyles.wordWrappedLabel);
126+
EditorGUILayout.SelectableLabel(val.ToString(), EditorStyles.wordWrappedLabel);
127+
}
117128
}
118129

119130
public override void OnInspectorGUI()

MLAPI/Data/NetworkedVar.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,42 @@ public string GetChannel()
201201
return Settings.SendChannel;
202202
}
203203
}
204+
205+
// These support serialization
206+
[Serializable]
207+
public class NetworkedVarBool : NetworkedVar<bool> { }
208+
[Serializable]
209+
public class NetworkedVarByte : NetworkedVar<byte> { }
210+
[Serializable]
211+
public class NetworkedVarSByte : NetworkedVar<sbyte> { }
212+
[Serializable]
213+
public class NetworkedVarUShort : NetworkedVar<ushort> { }
214+
[Serializable]
215+
public class NetworkedVarShort : NetworkedVar<short> { }
216+
[Serializable]
217+
public class NetworkedVarUInt : NetworkedVar<uint> { }
218+
[Serializable]
219+
public class NetworkedVarInt : NetworkedVar<int> { }
220+
[Serializable]
221+
public class NetworkedVarULong : NetworkedVar<ulong> { }
222+
[Serializable]
223+
public class NetworkedVarLong : NetworkedVar<long> { }
224+
[Serializable]
225+
public class NetworkedVarFloat : NetworkedVar<float> { }
226+
[Serializable]
227+
public class NetworkedVarDouble : NetworkedVar<double> { }
228+
[Serializable]
229+
public class NetworkedVarVector2 : NetworkedVar<Vector2> { }
230+
[Serializable]
231+
public class NetworkedVarVector3 : NetworkedVar<Vector3> { }
232+
[Serializable]
233+
public class NetworkedVarVector4 : NetworkedVar<Vector4> { }
234+
[Serializable]
235+
public class NetworkedVarColor : NetworkedVar<Color> { }
236+
[Serializable]
237+
public class NetworkedVarColor32 : NetworkedVar<Color32> { }
238+
[Serializable]
239+
public class NetworkedVarRay : NetworkedVar<Ray> { }
240+
[Serializable]
241+
public class NetworkedVarQuaternion : NetworkedVar<Quaternion> { }
204242
}

0 commit comments

Comments
 (0)