mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
split serialize
This commit is contained in:
parent
4033ce8d7f
commit
1d1749bd16
@ -186,6 +186,21 @@ void Update()
|
||||
else if (isClient) UpdateClient();
|
||||
}
|
||||
|
||||
void SerializeInitial(NetworkWriter writer, Vector3 position, Quaternion rotation, Vector3 scale)
|
||||
{
|
||||
if (syncPosition) writer.WriteVector3(position);
|
||||
if (syncRotation) writer.WriteQuaternion(rotation);
|
||||
if (syncScale) writer.WriteVector3(scale);
|
||||
}
|
||||
|
||||
void SerializeDelta(NetworkWriter writer, Vector3 position, Quaternion rotation, Vector3 scale)
|
||||
{
|
||||
// TODO changed mask, compression, etc.
|
||||
if (syncPosition) writer.WriteVector3(position);
|
||||
if (syncRotation) writer.WriteQuaternion(rotation);
|
||||
if (syncScale) writer.WriteVector3(scale);
|
||||
}
|
||||
|
||||
public override void OnSerialize(NetworkWriter writer, bool initialState)
|
||||
{
|
||||
// get position/rotation/scale from target transform once.
|
||||
@ -200,17 +215,12 @@ public override void OnSerialize(NetworkWriter writer, bool initialState)
|
||||
// (Spawn message wouldn't sync NTChild positions either)
|
||||
if (initialState)
|
||||
{
|
||||
if (syncPosition) writer.WriteVector3(current.position);
|
||||
if (syncRotation) writer.WriteQuaternion(current.rotation);
|
||||
if (syncScale) writer.WriteVector3(current.scale);
|
||||
SerializeInitial(writer, current.position, current.rotation, current.scale);
|
||||
}
|
||||
// otherwise only send what's changed
|
||||
else
|
||||
{
|
||||
// TODO changed mask, compression, etc.
|
||||
if (syncPosition) writer.WriteVector3(current.position);
|
||||
if (syncRotation) writer.WriteQuaternion(current.rotation);
|
||||
if (syncScale) writer.WriteVector3(current.scale);
|
||||
SerializeDelta(writer, current.position, current.rotation, current.scale);
|
||||
}
|
||||
|
||||
// either way, store last sent data for comparison
|
||||
|
Loading…
Reference in New Issue
Block a user