public void OnGsLiveRead(GsReadStream readStream) { try { if (synchronizePosition) { _mNetworkPosition = (Vector3)readStream.ReadNext(); _mDirection = (Vector3)readStream.ReadNext(); if (_mFirstTake) { transform.position = _mNetworkPosition; _mDistance = 0f; } else { var lag = (float)GsLiveRealtime.GetPing() / 100; _mNetworkPosition += _mDirection * lag; _mDistance = Vector3.Distance(transform.position, _mNetworkPosition); } } if (synchronizeRotation) { _mNetworkRotation = (Quaternion)readStream.ReadNext(); if (_mFirstTake) { _mAngle = 0f; transform.rotation = _mNetworkRotation; } else { _mAngle = Quaternion.Angle(transform.rotation, _mNetworkRotation); } } if (synchronizeScale) { transform.localScale = (Vector3)readStream.ReadNext(); } if (_mFirstTake) { _mFirstTake = false; } } catch (Exception e) { Debug.LogError("GSLiveTransformObserver OnGsLiveRead Error : " + e); } }
public void OnGsLiveRead(GsReadStream readStream) { try { _mNetworkPosition = (Vector2)readStream.ReadNext(); _mNetworkRotation = (float)readStream.ReadNext(); if (teleportEnabled) { if (Vector2.Distance(_rBody.position, _mNetworkPosition) > teleportIfDistanceGreaterThan) { _rBody.position = _mNetworkPosition; } } if (synchronizeVelocity || synchronizeAngularVelocity) { var lag = (float)GsLiveRealtime.GetPing() / 100; if (synchronizeVelocity) { _rBody.velocity = (Vector2)readStream.ReadNext(); _mNetworkPosition += _rBody.velocity * lag; _mDistance = Vector2.Distance(_rBody.position, _mNetworkPosition); } if (synchronizeAngularVelocity) { _rBody.angularVelocity = (float)readStream.ReadNext(); _mNetworkRotation += _rBody.angularVelocity * lag; _mAngle = Mathf.Abs(_rBody.rotation - _mNetworkRotation); } } } catch (Exception e) { Debug.LogError("RealtimeRigidbody2DObserver OnGsLiveRead Error : " + e); } }