Photon Unity Networking 2  2.8
English | 日本語 | 한국
Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
PhotonView Class Reference

A PhotonView identifies an object across the network (viewID) and configures how the controlling client updates remote instances. More...

Inherits MonoBehaviour.

Public Member Functions

void RequestOwnership ()
 Depending on the PhotonView's OwnershipTransfer setting, any client can request to become owner of the PhotonView. More...
 
void TransferOwnership (Player newOwner)
 Transfers the ownership of this PhotonView (and GameObject) to another player. More...
 
void TransferOwnership (int newOwnerId)
 Transfers the ownership of this PhotonView (and GameObject) to another player. More...
 
void SerializeView (PhotonStream stream, PhotonMessageInfo info)
 
void DeserializeView (PhotonStream stream, PhotonMessageInfo info)
 
void RefreshRpcMonoBehaviourCache ()
 Can be used to refesh the list of MonoBehaviours on this GameObject while PhotonNetwork.UseRpcMonoBehaviourCache is true. More...
 
void RPC (string methodName, RpcTarget target, params object[] parameters)
 Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client). More...
 
void RpcSecure (string methodName, RpcTarget target, bool encrypt, params object[] parameters)
 Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client). More...
 
void RPC (string methodName, Player targetPlayer, params object[] parameters)
 Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client). More...
 
void RpcSecure (string methodName, Player targetPlayer, bool encrypt, params object[] parameters)
 Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client). More...
 
override string ToString ()
 

Static Public Member Functions

static PhotonView Get (Component component)
 
static PhotonView Get (GameObject gameObj)
 
static PhotonView Find (int viewID)
 

Public Attributes

byte Group = 0
 
bool OwnershipWasTransfered
 Flag to check if ownership of this photonView was set during the lifecycle. Used for checking when joining late if event with mismatched owner and sender needs addressing. More...
 
int prefixField = -1
 
ViewSynchronization Synchronization
 
OwnershipOption OwnershipTransfer = OwnershipOption.Fixed
 Defines if ownership of this PhotonView is fixed, can be requested or simply taken. More...
 
List< Component > ObservedComponents
 
int InstantiationId
 

Properties

int Prefix [get, set]
 
object[] InstantiationData [get, set]
 This is the InstantiationData that was passed when calling PhotonNetwork.Instantiate* (if that was used to spawn this prefab) More...
 
int ViewID [get, set]
 The ID of the PhotonView. Identifies it in a networked game (per room). More...
 
bool IsSceneView [get]
 True if the PhotonView was loaded with the scene (game object) or instantiated with InstantiateSceneObject. More...
 
Player Owner [get]
 The owner of a PhotonView is the player who created the GameObject with that view. Objects in the scene don't have an owner. More...
 
int OwnerActorNr [get, set]
 
Player Controller [get]
 
int ControllerActorNr [get]
 
bool IsOwnerActive [get]
 
int CreatorActorNr [get]
 
bool IsMine [get]
 True if the PhotonView is "mine" and can be controlled by this client. More...
 

Detailed Description

A PhotonView identifies an object across the network (viewID) and configures how the controlling client updates remote instances.

Member Function Documentation

void RefreshRpcMonoBehaviourCache ( )

Can be used to refesh the list of MonoBehaviours on this GameObject while PhotonNetwork.UseRpcMonoBehaviourCache is true.

Set PhotonNetwork.UseRpcMonoBehaviourCache to true to enable the caching. Uses this.GetComponents<MonoBehaviour>() to get a list of MonoBehaviours to call RPCs on (potentially).

While PhotonNetwork.UseRpcMonoBehaviourCache is false, this method has no effect, because the list is refreshed when a RPC gets called.

void RequestOwnership ( )

Depending on the PhotonView's OwnershipTransfer setting, any client can request to become owner of the PhotonView.

Requesting ownership can give you control over a PhotonView, if the OwnershipTransfer setting allows that. The current owner might have to implement IPunCallbacks.OnOwnershipRequest to react to the ownership request.

The owner/controller of a PhotonView is also the client which sends position updates of the GameObject.

void RPC ( string  methodName,
RpcTarget  target,
params object[]  parameters 
)

Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client).

Remote Procedure Calls are an essential tool in making multiplayer games with PUN. It enables you to make every client in a room call a specific method.

RPC calls can target "All" or the "Others". Usually, the target "All" gets executed locally immediately after sending the RPC. The "*ViaServer" options send the RPC to the server and execute it on this client when it's sent back. Of course, calls are affected by this client's lag and that of remote clients.

Each call automatically is routed to the same PhotonView (and GameObject) that was used on the originating client.

See: Remote Procedure Calls.

Parameters
methodNameThe name of a fitting method that was has the RPC attribute.
targetThe group of targets and the way the RPC gets sent.
parametersThe parameters that the RPC method has (must fit this call!).
void RPC ( string  methodName,
Player  targetPlayer,
params object[]  parameters 
)

Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client).

Remote Procedure Calls are an essential tool in making multiplayer games with PUN. It enables you to make every client in a room call a specific method.

This method allows you to make an RPC calls on a specific player's client. Of course, calls are affected by this client's lag and that of remote clients.

Each call automatically is routed to the same PhotonView (and GameObject) that was used on the originating client.

See: Remote Procedure Calls.

Parameters
methodNameThe name of a fitting method that was has the RPC attribute.
targetPlayerThe group of targets and the way the RPC gets sent.
parametersThe parameters that the RPC method has (must fit this call!).
void RpcSecure ( string  methodName,
RpcTarget  target,
bool  encrypt,
params object[]  parameters 
)

Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client).

Remote Procedure Calls are an essential tool in making multiplayer games with PUN. It enables you to make every client in a room call a specific method.

RPC calls can target "All" or the "Others". Usually, the target "All" gets executed locally immediately after sending the RPC. The "*ViaServer" options send the RPC to the server and execute it on this client when it's sent back. Of course, calls are affected by this client's lag and that of remote clients.

Each call automatically is routed to the same PhotonView (and GameObject) that was used on the originating client.

See: Remote Procedure Calls.

param name="methodName">The name of a fitting method that was has the RPC attribute.

param name="target">The group of targets and the way the RPC gets sent.

param name="encrypt">

param name="parameters">The parameters that the RPC method has (must fit this call!).

void RpcSecure ( string  methodName,
Player  targetPlayer,
bool  encrypt,
params object[]  parameters 
)

Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client).

Remote Procedure Calls are an essential tool in making multiplayer games with PUN. It enables you to make every client in a room call a specific method.

This method allows you to make an RPC calls on a specific player's client. Of course, calls are affected by this client's lag and that of remote clients.

Each call automatically is routed to the same PhotonView (and GameObject) that was used on the originating client.

See: Remote Procedure Calls.

param name="methodName">The name of a fitting method that was has the RPC attribute.

param name="targetPlayer">The group of targets and the way the RPC gets sent.

param name="encrypt">

param name="parameters">The parameters that the RPC method has (must fit this call!).

void TransferOwnership ( Player  newOwner)

Transfers the ownership of this PhotonView (and GameObject) to another player.

The owner/controller of a PhotonView is also the client which sends position updates of the GameObject.

void TransferOwnership ( int  newOwnerId)

Transfers the ownership of this PhotonView (and GameObject) to another player.

The owner/controller of a PhotonView is also the client which sends position updates of the GameObject.

Member Data Documentation

Defines if ownership of this PhotonView is fixed, can be requested or simply taken.

Note that you can't edit this value at runtime. The options are described in enum OwnershipOption. The current owner has to implement IPunCallbacks.OnOwnershipRequest to react to the ownership request.

bool OwnershipWasTransfered

Flag to check if ownership of this photonView was set during the lifecycle. Used for checking when joining late if event with mismatched owner and sender needs addressing.

true if owner ship was transfered; otherwise, false.

Property Documentation

object [] InstantiationData
getset

This is the InstantiationData that was passed when calling PhotonNetwork.Instantiate* (if that was used to spawn this prefab)

bool IsMine
get

True if the PhotonView is "mine" and can be controlled by this client.

PUN has an ownership concept that defines who can control and destroy each PhotonView. True in case the owner matches the local Player. True if this is a scene photonview on the Master client.

bool IsSceneView
get

True if the PhotonView was loaded with the scene (game object) or instantiated with InstantiateSceneObject.

Scene objects are not owned by a particular player but belong to the scene. Thus they don't get destroyed when their creator leaves the game and the current Master Client can control them (whoever that is). The ownerId is 0 (player IDs are 1 and up).

Player Owner
get

The owner of a PhotonView is the player who created the GameObject with that view. Objects in the scene don't have an owner.

The owner/controller of a PhotonView is also the client which sends position updates of the GameObject.

Ownership can be transferred to another player with PhotonView.TransferOwnership or any player can request ownership by calling the PhotonView's RequestOwnership method. The current owner has to implement IPunCallbacks.OnOwnershipRequest to react to the ownership request.

int ViewID
getset

The ID of the PhotonView. Identifies it in a networked game (per room).

See: Network Instantiation