CommunicationBridge Class

Holds references and methods for communications with active Multiplayer component. Unlike CommunicationBridgeUID, this component does not have a unique identifier (UID).

Definition

Namespace: Alteruna
Assembly: Alteruna.Trinity (in Alteruna.Trinity.dll) Version: 1.3.4
C#
public abstract class CommunicationBridge : MonoBehaviour
Inheritance
Object    Object    Component    Behaviour    MonoBehaviour    CommunicationBridge
Derived
More

Example

The CommunicationBridge class can be used to get a Multiplayer reference and possession of avatars.
C#
public class MyCommunicationBridge : CommunicationBridge
{
    private bool _isPossessed = false;
    private bool _isPossessor = false;
    private Avatar _avatar;

    // The possessed event is called after awake and before start when the avatar is initialized.
    public override void Possessed(bool isMe, User user)
    {
        _isPossessed = true;

        // also known as is owner
        _isPossessor = isMe;

        // Inside CommunicationBridge, we can access the Multiplayer component through the Multiplayer property.
        // We can use it to get the avatar for a user.
        _avatar = Multiplayer.GetAvatar(user.Index);
    }

    // When the player is removed form the game or the avatar is repossessed, we can manage it using the Unpossessed method.
    public override void Unpossessed()
    {
        _isPossessed = false;
        _isPossessor = false;
        _avatar = null;
    }
}

Methods

OnEnable Collects Multiplayer reference.
Possessed Called when Avatar is possessed by a user.
Reset We set the Multiplayer reference when component is reset inorder to save performance in the spawn frame.
SetMultiplayerComponent If the Multiplayer reference is null, set it to active Multiplayer component.

Example

C#
void OnEnable() => SetMultiplayerComponent();
SetMultiplayerComponent call it in OnEnable unless hidden.
Unpossessed Called when Avatar gets unpossessed.

Fields

Multiplayer Reference to Multiplayer controller component. sets in OnEnable unless hidden.

See Also