private static void _BindTransform(ref NetworkObserved observed) { var transform = (Transform)observed.component; Serializer serializer = delegate(BitStream stream, NetworkMessageInfo info) { if (stream.isReading) { transform.localPosition = stream.ReadVector3(); transform.localRotation = stream.ReadQuaternion(); transform.localScale = stream.ReadVector3(); } else { stream.WriteVector3(transform.localPosition); stream.WriteQuaternion(transform.localRotation); stream.WriteVector3(transform.localScale); } }; observed.serializeProxy = serializer; observed.serializeOwner = serializer; observed.serializeHandover = serializer; observed.serializeCellProxy = serializer; }
public static void DefaultBinder(ref NetworkObserved observed) { Type type = observed.component.GetType(); observed.serializeProxy = CreateSerializer(observed.component, type, EVENT_SERIALIZE_PROXY); observed.serializeOwner = CreateSerializer(observed.component, type, EVENT_SERIALIZE_OWNER); observed.serializeHandover = CreateSerializer(observed.component, type, EVENT_SERIALIZE_HANDOVER); observed.serializeCellProxy = CreateSerializer(observed.component, type, EVENT_SERIALIZE_CELLPROXY); }
private static void _BindRigidbody(ref NetworkObserved observed) { var rigidbody = (Rigidbody)observed.component; Serializer serializer = delegate(BitStream stream, NetworkMessageInfo info) { if (stream.isReading) { float transitTime = (float)(Network.time - info.timestamp); Vector3 newPos = stream.ReadVector3(); Quaternion newRot = stream.ReadQuaternion(); Vector3 newVel = stream.ReadVector3(); Vector3 angVel = stream.ReadVector3(); newRot.eulerAngles += angVel * transitTime; rigidbody.angularVelocity = angVel; Vector3 gravity = rigidbody.useGravity ? Physics.gravity : Vector3.zero; newPos += newVel * transitTime + gravity * transitTime * transitTime * 0.5f; newVel += gravity * transitTime; if ((rigidbody.position - newPos).sqrMagnitude >= RIGIDBODY_POS_MAXSQRERROR) { rigidbody.position = newPos; } if ((rigidbody.velocity - newVel).sqrMagnitude >= RIGIDBODY_VEL_MAXSQRERROR) { rigidbody.velocity = newVel; } if (Quaternion.Angle(rigidbody.rotation, newRot) >= RIGIDBODY_ROT_MAXERROR) { rigidbody.rotation = newRot; } } else { stream.WriteVector3(rigidbody.position); stream.WriteQuaternion(rigidbody.rotation); stream.WriteVector3(rigidbody.velocity); stream.WriteVector3(rigidbody.angularVelocity); } }; observed.serializeProxy = serializer; observed.serializeOwner = serializer; observed.serializeHandover = serializer; observed.serializeCellProxy = serializer; }
private void _CheckList() { if (_list == null || _list.Length != observedList.Length) { _list = new uLink.NetworkObserved[observedList.Length]; for (int i = 0; i < observedList.Length; i++) { _list[i] = new uLink.NetworkObserved(observedList[i]); } } else { for (int i = 0; i < observedList.Length; i++) { _list[i].UpdateBinding(observedList[i]); } } }
private static void _BindAnimation(ref NetworkObserved observed) { var animation = (Animation)observed.component; Serializer serializer = delegate(BitStream stream, NetworkMessageInfo info) { if (stream.isReading) { float transitTime = (float)(Network.time - info.timestamp); foreach (AnimationState state in animation) { state.enabled = stream.ReadBoolean(); float newTime = stream.ReadSingle() + transitTime; state.speed = stream.ReadSingle(); state.weight = stream.ReadSingle(); if (Mathf.Abs(state.time - newTime) >= ANIMATION_TIME_MAXERROR) { state.time = newTime; } } } else { foreach (AnimationState state in animation) { stream.WriteBoolean(state.enabled); stream.WriteSingle(state.time); stream.WriteSingle(state.speed); stream.WriteSingle(state.weight); } } }; observed.serializeProxy = serializer; observed.serializeOwner = serializer; observed.serializeHandover = serializer; observed.serializeCellProxy = serializer; }
private void _CheckList() { if (_list == null || _list.Length != observedList.Length) { _list = new uLink.NetworkObserved[observedList.Length]; for (int i = 0; i < observedList.Length; i++) { _list[i] = new uLink.NetworkObserved(observedList[i]); } } else { for (int i = 0; i < observedList.Length; i++) { _list[i].UpdateBinding(observedList[i]); } } }