Photon Unity Networking v1.101

Public Member Functions | Public Attributes | List of all members
PhotonTransformView Class Reference

This class helps you to synchronize position, rotation and scale of a GameObject. It also gives you many different options to make the synchronized values appear smooth, even when the data is only send a couple of times per second. Simply add the component to your GameObject and make sure that the PhotonTransformView is added to the list of observed components More...

Inherits MonoBehaviour, and IPunObservable.

Public Member Functions

void SetSynchronizedValues (Vector3 speed, float turnSpeed)
 These values are synchronized to the remote objects if the interpolation mode or the extrapolation mode SynchronizeValues is used. Your movement script should pass on the current speed (in units/second) and turning speed (in angles/second) so the remote object can use them to predict the objects movement. More...
 
void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)
 Called by PUN several times per second, so that your script can write and read synchronization data for the PhotonView. More...
 

Public Attributes

PhotonTransformViewPositionModel m_PositionModel = new PhotonTransformViewPositionModel()
 
PhotonTransformViewRotationModel m_RotationModel = new PhotonTransformViewRotationModel()
 
PhotonTransformViewScaleModel m_ScaleModel = new PhotonTransformViewScaleModel()
 

Detailed Description

This class helps you to synchronize position, rotation and scale of a GameObject. It also gives you many different options to make the synchronized values appear smooth, even when the data is only send a couple of times per second. Simply add the component to your GameObject and make sure that the PhotonTransformView is added to the list of observed components

Member Function Documentation

◆ OnPhotonSerializeView()

void PhotonTransformView.OnPhotonSerializeView ( PhotonStream  stream,
PhotonMessageInfo  info 
)

Called by PUN several times per second, so that your script can write and read synchronization data for the PhotonView.

This method will be called in scripts that are assigned as Observed component of a PhotonView.
PhotonNetwork.sendRateOnSerialize affects how often this method is called.
PhotonNetwork.sendRate affects how often packages are sent by this client.

Implementing this method, you can customize which data a PhotonView regularly synchronizes. Your code defines what is being sent (content) and how your data is used by receiving clients.

Unlike other callbacks, OnPhotonSerializeView only gets called when it is assigned to a PhotonView as PhotonView.observed script.

To make use of this method, the PhotonStream is essential. It will be in "writing" mode" on the client that controls a PhotonView (PhotonStream.isWriting == true) and in "reading mode" on the remote clients that just receive that the controlling client sends.

If you skip writing any value into the stream, PUN will skip the update. Used carefully, this can conserve bandwidth and messages (which have a limit per room/second).

Note that OnPhotonSerializeView is not called on remote clients when the sender does not send any update. This can't be used as "x-times per second Update()".

Implements IPunObservable.

◆ SetSynchronizedValues()

void PhotonTransformView.SetSynchronizedValues ( Vector3  speed,
float  turnSpeed 
)

These values are synchronized to the remote objects if the interpolation mode or the extrapolation mode SynchronizeValues is used. Your movement script should pass on the current speed (in units/second) and turning speed (in angles/second) so the remote object can use them to predict the objects movement.

Parameters
speedThe current movement vector of the object in units/second.
turnSpeedThe current turn speed of the object in angles/second.

Member Data Documentation

◆ m_PositionModel

PhotonTransformViewPositionModel PhotonTransformView.m_PositionModel = new PhotonTransformViewPositionModel()

◆ m_RotationModel

PhotonTransformViewRotationModel PhotonTransformView.m_RotationModel = new PhotonTransformViewRotationModel()

◆ m_ScaleModel

PhotonTransformViewScaleModel PhotonTransformView.m_ScaleModel = new PhotonTransformViewScaleModel()