/// <summary> /// Calculates an estimated position based on the last synchronized position, /// the time when the last position was received and the movement speed of the object /// </summary> /// <returns>Estimated position of the remote object</returns> public Vector3 GetExtrapolatedPositionOffset() { float timePassed = (float)(PhotonNetworkManager.time - m_LastSerializeTime); if (m_Model.ExtrapolateIncludingRoundTripTime == true) { timePassed += (float)PhotonNetworkManager.GetPing() / 1000f; } Vector3 extrapolatePosition = Vector3.zero; switch (m_Model.ExtrapolateOption) { case PhotonTransformViewPositionModel.ExtrapolateOptions.SynchronizeValues: Quaternion turnRotation = Quaternion.Euler(0, m_SynchronizedTurnSpeed * timePassed, 0); extrapolatePosition = turnRotation * (m_SynchronizedSpeed * timePassed); break; case PhotonTransformViewPositionModel.ExtrapolateOptions.FixedSpeed: Vector3 moveDirection = (m_NetworkPosition - GetOldestStoredNetworkPosition()).normalized; extrapolatePosition = moveDirection * m_Model.ExtrapolateSpeed * timePassed; break; case PhotonTransformViewPositionModel.ExtrapolateOptions.EstimateSpeedAndTurn: Vector3 moveDelta = (m_NetworkPosition - GetOldestStoredNetworkPosition()) * PhotonNetworkManager.sendRateOnSerialize; extrapolatePosition = moveDelta * timePassed; break; } return(extrapolatePosition); }
public void OnGUI() { if (this.Skin != null) { GUI.skin = this.Skin; } if (PhotonNetworkManager.isMasterClient) { GUILayout.Label("Controlling client.\nPing: " + PhotonNetworkManager.GetPing()); if (GUILayout.Button("disconnect", GUILayout.ExpandWidth(false))) { PhotonNetworkManager.Disconnect(); } } else if (PhotonNetworkManager.isNonMasterClientInRoom) { GUILayout.Label("Receiving updates.\nPing: " + PhotonNetworkManager.GetPing()); if (GUILayout.Button("disconnect", GUILayout.ExpandWidth(false))) { PhotonNetworkManager.Disconnect(); } } else { GUILayout.Label("Not in room yet\n" + PhotonNetworkManager.connectionStateDetailed); } if (!PhotonNetworkManager.connected && !PhotonNetworkManager.connecting) { if (GUILayout.Button("connect", GUILayout.Width(80))) { PhotonNetworkManager.ConnectUsingSettings(null); // using null as parameter, re-uses previously set version. } } }