public void PopulateMessage(NetworkIdentity identity) { this.NetworkId = identity.NetworkId; this.OwnerId = identity.OwnerId; this.IsEnabled = identity.gameObject.activeSelf; this.ResourceName = identity.ResourceName; this.CanChangeOwner = identity.CanChangeOwner; this.Position = NetworkTransformAnchor.InverseTransformPosition(identity.transform.position); this.Rotation = NetworkTransformAnchor.InverseTransformRotation(identity.transform.rotation); }
public override void Serialize(NetworkWriter writer) { bool sendPhysics = this.rigidBody != null; bool useGravity = sendPhysics && this.rigidBody.useGravity; bool freezeRotation = sendPhysics && this.rigidBody.freezeRotation; bool isKinematic = sendPhysics && this.rigidBody.isKinematic; int sent = 0; NetworkUtil.SetBit(ref sent, 0, this.sendPosition); NetworkUtil.SetBit(ref sent, 1, this.sendRotation); NetworkUtil.SetBit(ref sent, 2, this.sendScale); NetworkUtil.SetBit(ref sent, 3, sendPhysics); NetworkUtil.SetBit(ref sent, 4, useGravity); NetworkUtil.SetBit(ref sent, 5, freezeRotation); NetworkUtil.SetBit(ref sent, 6, isKinematic); writer.WritePackedUInt32(++this.version); writer.WritePackedUInt32((uint)sent); if (this.sendPosition) { writer.Write(NetworkTransformAnchor.InverseTransformPosition(this.transform.position)); } if (this.sendRotation) { writer.Write(NetworkTransformAnchor.InverseTransformRotation(this.transform.rotation)); } if (this.sendScale) { writer.Write(this.transform.localScale); } if (sendPhysics) { writer.Write(this.rigidBody.velocity); } }