Added support for Vector3,Vector2 and Quaternion's in SyncVars
This commit is contained in:
parent
7b9d2d14a7
commit
0d47c6980b
@ -14,6 +14,9 @@
|
||||
UInt,
|
||||
ULong,
|
||||
UShort,
|
||||
String
|
||||
String,
|
||||
Vector3,
|
||||
Vector2,
|
||||
Quaternion
|
||||
}
|
||||
}
|
||||
|
@ -222,6 +222,24 @@ namespace MLAPI
|
||||
syncedFieldValues.Add(sortedFields[i].GetValue(this));
|
||||
syncedFieldTypes.Add(FieldType.String);
|
||||
}
|
||||
else if(sortedFields[i].FieldType == typeof(Vector3))
|
||||
{
|
||||
syncedFields.Add(sortedFields[i]);
|
||||
syncedFieldValues.Add(sortedFields[i].GetValue(this));
|
||||
syncedFieldTypes.Add(FieldType.Vector3);
|
||||
}
|
||||
else if(sortedFields[i].FieldType == typeof(Vector2))
|
||||
{
|
||||
syncedFields.Add(sortedFields[i]);
|
||||
syncedFieldValues.Add(sortedFields[i].GetValue(this));
|
||||
syncedFieldTypes.Add(FieldType.Vector2);
|
||||
}
|
||||
else if (sortedFields[i].FieldType == typeof(Quaternion))
|
||||
{
|
||||
syncedFields.Add(sortedFields[i]);
|
||||
syncedFieldValues.Add(sortedFields[i].GetValue(this));
|
||||
syncedFieldTypes.Add(FieldType.Quaternion);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("MLAPI: The type " + sortedFields[i].FieldType.ToString() + " can not be used as a syncvar");
|
||||
@ -299,6 +317,23 @@ namespace MLAPI
|
||||
case FieldType.String:
|
||||
writer.Write((string)syncedFields[i].GetValue(this));
|
||||
break;
|
||||
case FieldType.Vector3:
|
||||
Vector3 vector3 = (Vector3)syncedFields[i].GetValue(this);
|
||||
writer.Write(vector3.x);
|
||||
writer.Write(vector3.y);
|
||||
writer.Write(vector3.z);
|
||||
break;
|
||||
case FieldType.Vector2:
|
||||
Vector2 vector2 = (Vector2)syncedFields[i].GetValue(this);
|
||||
writer.Write(vector2.x);
|
||||
writer.Write(vector2.y);
|
||||
break;
|
||||
case FieldType.Quaternion:
|
||||
Vector3 euler = ((Quaternion)syncedFields[i].GetValue(this)).eulerAngles;
|
||||
writer.Write(euler.x);
|
||||
writer.Write(euler.y);
|
||||
writer.Write(euler.z);
|
||||
break;
|
||||
}
|
||||
}
|
||||
NetworkingManager.singleton.Send(clientId, "MLAPI_SYNC_VAR_UPDATE", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.ToArray());
|
||||
@ -372,6 +407,24 @@ namespace MLAPI
|
||||
case FieldType.String:
|
||||
writer.Write((string)syncedFields[i].GetValue(this));
|
||||
break;
|
||||
case FieldType.Vector3:
|
||||
Vector3 vector3 = (Vector3)syncedFields[i].GetValue(this);
|
||||
writer.Write(vector3.x);
|
||||
writer.Write(vector3.y);
|
||||
writer.Write(vector3.z);
|
||||
break;
|
||||
case FieldType.Vector2:
|
||||
Vector2 vector2 = (Vector2)syncedFields[i].GetValue(this);
|
||||
writer.Write(vector2.x);
|
||||
writer.Write(vector2.y);
|
||||
break;
|
||||
case FieldType.Quaternion:
|
||||
Vector3 euler = ((Quaternion)syncedFields[i].GetValue(this)).eulerAngles;
|
||||
writer.Write(euler.x);
|
||||
writer.Write(euler.y);
|
||||
writer.Write(euler.z);
|
||||
break;
|
||||
|
||||
}
|
||||
syncedFieldValues[i] = syncedFields[i].GetValue(this);
|
||||
dirtyFields[i] = false;
|
||||
@ -470,6 +523,24 @@ namespace MLAPI
|
||||
else
|
||||
dirtyFields[i] = false; //Up to date
|
||||
break;
|
||||
case FieldType.Vector3:
|
||||
if ((Vector3)syncedFields[i].GetValue(this) != (Vector3)syncedFieldValues[i])
|
||||
dirtyFields[i] = true; //This fields value is out of sync!
|
||||
else
|
||||
dirtyFields[i] = false; //Up to date
|
||||
break;
|
||||
case FieldType.Vector2:
|
||||
if ((Vector2)syncedFields[i].GetValue(this) != (Vector2)syncedFieldValues[i])
|
||||
dirtyFields[i] = true; //This fields value is out of sync!
|
||||
else
|
||||
dirtyFields[i] = false; //Up to date
|
||||
break;
|
||||
case FieldType.Quaternion:
|
||||
if ((Quaternion)syncedFields[i].GetValue(this) != (Quaternion)syncedFieldValues[i])
|
||||
dirtyFields[i] = true; //This fields value is out of sync!
|
||||
else
|
||||
dirtyFields[i] = false; //Up to date
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -741,6 +741,29 @@ namespace MLAPI
|
||||
case FieldType.String:
|
||||
SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).OnSyncVarUpdate(messageReader.ReadString(), fieldIndex);
|
||||
break;
|
||||
case FieldType.Vector3:
|
||||
{ //Cases aren't their own scope. Therefor we create a scope for them as they share the X,Y,Z local variables otherwise.
|
||||
float x = messageReader.ReadSingle();
|
||||
float y = messageReader.ReadSingle();
|
||||
float z = messageReader.ReadSingle();
|
||||
SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).OnSyncVarUpdate(new Vector3(x, y, z), fieldIndex);
|
||||
}
|
||||
break;
|
||||
case FieldType.Vector2:
|
||||
{
|
||||
float x = messageReader.ReadSingle();
|
||||
float y = messageReader.ReadSingle();
|
||||
SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).OnSyncVarUpdate(new Vector2(x, y), fieldIndex);
|
||||
}
|
||||
break;
|
||||
case FieldType.Quaternion:
|
||||
{
|
||||
float x = messageReader.ReadSingle();
|
||||
float y = messageReader.ReadSingle();
|
||||
float z = messageReader.ReadSingle();
|
||||
SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).OnSyncVarUpdate(Quaternion.Euler(x, y, z), fieldIndex);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user