/// <summary> /// Handles a <see cref="RigidbodySyncData"/> update. Only called on clients. /// </summary> /// <param name="syncData">The synchronized data.</param> public void HandleUpdate(RigidbodySyncData syncData, bool initialSetup = false) { if (!_interpolate || initialSetup) { _rb.velocity = syncData.velocity; _rb.angularVelocity = syncData.angularVelocity; this.transform.position = syncData.position; this.transform.rotation = syncData.rotation; } else { _hasBeenUpdated = true; if (_targetPosition == Vector3.zero) { _lastSyncPos = syncData.position; } else { _lastSyncPos = _targetPosition; } if (_targetRotation.IsZero()) { _lastSyncRot = syncData.rotation; } else { _lastSyncRot = _targetRotation; } if (_targetVel == Vector3.zero) { _lastSyncVel = syncData.velocity; } else { _lastSyncVel = _targetVel; } if (_targetAV == Vector3.zero) { _lastSyncAV = syncData.angularVelocity; } else { _lastSyncAV = _targetAV; } _targetPosition = syncData.position; _targetRotation = syncData.rotation; _targetVel = syncData.velocity; _targetAV = syncData.angularVelocity; _prevSyncTime = _lastSyncTime; _lastSyncTime = Time.timeSinceLevelLoad; _framesLerped = 0; } }
protected override void Deserialize(NetDeserializer s) { this.data = new RigidbodySyncData() { syncId = s.ReadInt(), prefabType = s.ReadPrefabType(), position = s.ReadExactVector3(), rotation = s.ReadQuaternion() }; }
// position already updated to RemotePos(d) private RigidbodySyncComponent NewRigidbodySync(RigidbodySyncData data) { var prefab = PrefabManager.instance.Spawn(data.prefabType, data.position, data.rotation); if (prefab == null) { Debug.LogError(this.ToString() + " NewRigidbodySync missing prefab setup for prefab of type == " + data.prefabType.ToString()); return(null); } var rb = prefab.gameObject.GetComponent <RigidbodySyncComponent>(); if (rb == null) { rb = prefab.gameObject.AddComponent <RigidbodySyncComponent>(); Debug.LogWarning(this.ToString() + " NewRigidbodySync prefab missing a RigidbodySyncComponent, prefab == " + prefab.ToString() + ", adding the component automatically."); } rb.Initialize(data.syncId); return(rb); }