public static BoneSyncData DeSerialize(NetworkReader reader) { var boneSyncData = new BoneSyncData(); boneSyncData.boneId = reader.ReadByte(); boneSyncData.position = reader.ReadVector3(); boneSyncData.rotation = reader.ReadVector3(); if (boneSyncData.boneId == 0) { boneSyncData.velocity = reader.ReadVector3(); } return(boneSyncData); }
public override void OnDeserialize(NetworkReader reader, bool initialState) { if (initialState) { m_net_modelId = reader.ReadInt32(); } byte flags = reader.ReadByte(); byte count = reader.ReadByte(); m_bonesSyncData.EnsureCount(count); for (int i = 0; i < count; i++) { m_bonesSyncData[i] = BoneSyncData.DeSerialize(reader); } F.RunExceptionSafe(() => UpdateBonesAfterDeserialization(count)); }
public override bool OnSerialize(NetworkWriter writer, bool initialState) { if (initialState) { writer.Write(m_net_modelId); } byte flags = 0; writer.Write(flags); Dictionary <int, BoneInfo> bonesDict = initialState ? m_framesDict : m_rigidBodiesDict; bool checkRigidBodyForNull = initialState; writer.Write((byte)bonesDict.Count); foreach (var pair in bonesDict) { int boneId = pair.Key; Transform tr = pair.Value.Transform; Rigidbody rb = pair.Value.Rigidbody; var boneSyncData = new BoneSyncData(); boneSyncData.boneId = (byte)boneId; boneSyncData.position = tr.localPosition; boneSyncData.rotation = tr.localRotation.eulerAngles; if (checkRigidBodyForNull) { boneSyncData.velocity = rb != null?GetVelocityForSending(rb) : Vector3.zero; } else { boneSyncData.velocity = GetVelocityForSending(rb); } boneSyncData.Serialize(writer); } return(true); }