Photon Fusion 2.0.3

Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
PlayerRef Struct Reference

Represents a Fusion player. More...

Inherits INetworkStruct, and IEquatable< PlayerRef >.

Public Member Functions

override bool Equals (object obj)
 Determines whether the specified object is equal to the current object. More...
 
bool Equals (PlayerRef other)
 Determines whether the specified PlayerRef is equal to the current PlayerRef. More...
 
override int GetHashCode ()
 Serves as the default hash function. More...
 
override string ToString ()
 Returns a string that represents the current object. More...
 

Static Public Member Functions

static PlayerRef FromEncoded (int encoded)
 Creates a new PlayerRef from the given encoded value. More...
 
static PlayerRef FromIndex (int index)
 Creates a new PlayerRef from the given index. More...
 
static bool operator!= (PlayerRef a, PlayerRef b)
 Determines whether two PlayerRef instances are not equal. More...
 
static bool operator== (PlayerRef a, PlayerRef b)
 Determines whether two PlayerRef instances are equal. More...
 
static unsafe PlayerRef Read (NetBitBuffer *buffer)
 Reads a PlayerRef from the provided NetBitBuffer. More...
 
static unsafe void Write (NetBitBuffer *buffer, PlayerRef playerRef)
 Writes the PlayerRef to the provided NetBitBuffer. More...
 
static unsafe void Write< T > (T *buffer, PlayerRef playerRef)
 Writes the PlayerRef to the provided buffer. More...
 

Public Attributes

int _index
 

Static Public Attributes

const int MASTER_CLIENT_RAW = -1
 A constant representing the raw index value for the master client. More...
 
const int SIZE = 4
 The size of the PlayerRef structure in bytes. More...
 

Properties

int AsIndex [get]
 Returns the PlayerRef int as an integer Id value. More...
 
static IEqualityComparer< PlayerRefComparer = new IndexEqualityComparer() [get]
 Gets an equality comparer that can be used to compare two PlayerRef instances. More...
 
static PlayerRef Invalid [get]
 Invalid player ref. Used to differentiate no player ref (None) from an invalid one. More...
 
bool IsMasterClient [get]
 Returns true if this PlayerRef indicates the MasterClient rather than a specific Player by Index, This is a special flag value which has the encoded index value of -2 (internal raw backing value of -1). This is not a valid PlayerRef value in itself, and no Runner will ever be assigned this value as its LocalPlayer. It is used by properties like Object.StateAuthority to indicate that the MasterClient has authority (which ever player that currently is), rather than a specific Player. More...
 
bool IsNone [get]
 Returns true if the index value equals -1 (internal raw value of 0), indicating no player. More...
 
bool IsRealPlayer [get]
 If this player ref is a valid unique player index More...
 
static PlayerRef MasterClient [get]
 Special master client player ref value of -1 More...
 
static PlayerRef None [get]
 None player More...
 
int PlayerId [get]
 Returns the PlayerRef as an integer Id value. More...
 
int RawEncoded [get]
 Returns the index backing value without modification. Unlike AsIndex which returns the backing value - 1. More...
 

Detailed Description

Represents a Fusion player.

The PlayerRef, in contrast to the player index, is 1-based. The reason is that default(PlayerRef) will return a "null/invalid" player ref struct for convenience. There are automatic cast operators that can cast an int into a PlayerRef.

default(PlayerRef), internally a 0, means NOBODY
PlayerRef, internally 1, is the same as player index 0
PlayerRef, internally 2, is the same as player index 1

Member Function Documentation

◆ Equals() [1/2]

override bool Equals ( object  obj)

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object; otherwise, false.

◆ Equals() [2/2]

bool Equals ( PlayerRef  other)

Determines whether the specified PlayerRef is equal to the current PlayerRef.

Parameters
otherThe PlayerRef to compare with the current PlayerRef.
Returns
true if the specified PlayerRef is equal to the current PlayerRef; otherwise, false.

◆ FromEncoded()

static PlayerRef FromEncoded ( int  encoded)
static

Creates a new PlayerRef from the given encoded value.

Parameters
encodedThe encoded value to create the PlayerRef from.
Returns
A new PlayerRef that represents the encoded value.

◆ FromIndex()

static PlayerRef FromIndex ( int  index)
static

Creates a new PlayerRef from the given index.

Parameters
indexThe index to create the PlayerRef from.
Returns
A new PlayerRef that represents the index.

◆ GetHashCode()

override int GetHashCode ( )

Serves as the default hash function.

◆ operator!=()

static bool operator!= ( PlayerRef  a,
PlayerRef  b 
)
static

Determines whether two PlayerRef instances are not equal.

Parameters
aThe first PlayerRef to compare.
bThe second PlayerRef to compare.
Returns
true if the PlayerRefs are not equal; otherwise, false.

◆ operator==()

static bool operator== ( PlayerRef  a,
PlayerRef  b 
)
static

Determines whether two PlayerRef instances are equal.

Parameters
aThe first PlayerRef to compare.
bThe second PlayerRef to compare.
Returns
true if the PlayerRefs are equal; otherwise, false.

◆ Read()

static unsafe PlayerRef Read ( NetBitBuffer buffer)
static

Reads a PlayerRef from the provided NetBitBuffer.

Parameters
bufferThe buffer to read from.
Returns
The PlayerRef read from the buffer.

◆ ToString()

override string ToString ( )

Returns a string that represents the current object.

◆ Write()

static unsafe void Write ( NetBitBuffer buffer,
PlayerRef  playerRef 
)
static

Writes the PlayerRef to the provided NetBitBuffer.

Parameters
bufferThe buffer to write to.
playerRefThe PlayerRef to write.

◆ Write< T >()

static unsafe void Write< T > ( T *  buffer,
PlayerRef  playerRef 
)
static

Writes the PlayerRef to the provided buffer.

Template Parameters
TThe type of the buffer. Must be unmanaged and implement INetBitWriteStream.
Parameters
bufferThe buffer to write to.
playerRefThe PlayerRef to write.
Type Constraints
T :unmanaged 
T :INetBitWriteStream 

Member Data Documentation

◆ MASTER_CLIENT_RAW

const int MASTER_CLIENT_RAW = -1
static

A constant representing the raw index value for the master client.

◆ SIZE

const int SIZE = 4
static

The size of the PlayerRef structure in bytes.

Property Documentation

◆ AsIndex

int AsIndex
get

Returns the PlayerRef int as an integer Id value.

-1=None -2=MasterClient >=0=PlayerId

◆ Comparer

IEqualityComparer<PlayerRef> Comparer = new IndexEqualityComparer()
staticget

Gets an equality comparer that can be used to compare two PlayerRef instances.

◆ Invalid

PlayerRef Invalid
staticget

Invalid player ref. Used to differentiate no player ref (None) from an invalid one.

◆ IsMasterClient

bool IsMasterClient
get

Returns true if this PlayerRef indicates the MasterClient rather than a specific Player by Index, This is a special flag value which has the encoded index value of -2 (internal raw backing value of -1). This is not a valid PlayerRef value in itself, and no Runner will ever be assigned this value as its LocalPlayer. It is used by properties like Object.StateAuthority to indicate that the MasterClient has authority (which ever player that currently is), rather than a specific Player.

◆ IsNone

bool IsNone
get

Returns true if the index value equals -1 (internal raw value of 0), indicating no player.

◆ IsRealPlayer

bool IsRealPlayer
get

If this player ref is a valid unique player index

◆ MasterClient

PlayerRef MasterClient
staticget

Special master client player ref value of -1

◆ None

PlayerRef None
staticget

None player

◆ PlayerId

int PlayerId
get

Returns the PlayerRef as an integer Id value.

-1=None -2=MasterClient

◆ RawEncoded

int RawEncoded
get

Returns the index backing value without modification. Unlike AsIndex which returns the backing value - 1.

0=None -1=MasterClient >0=PlayerId