CommunicationBridge Class

The base class for many of Alteruna Multiplayer's components.

Definition

Namespace: Alteruna.Multiplayer
Assembly: Alteruna (in Alteruna.dll) Version: 2.0.1+a1176e08a0b4a6bfd8fefeddde6163a16d29e5ab
C#
public abstract class CommunicationBridge : MonoBehaviour
Inheritance
Object    Object    Component    Behaviour    MonoBehaviour    CommunicationBridge
Derived
More

Remarks

CommunicationBridge provides an easy way to get a reference of your MultiplayerManager and provides your class with methods used for possession. Unlike CommunicationBridgeUID, this component does not have a unique identifier (UID).

Example

C#
public class MyCommunicationBridge : CommunicationBridge
{
    private bool _isPossessed;
    private bool _isPossessor;
    private Avatar _avatar;

    // The Possessed method is called after awake and before start when the avatar is initialized.
    // When the user who possesses the object is the local player, isMe is true.
    public override void Possessed(bool isMe, User user)
    {
        // Since this method is called from a remote event, we know that the game object is possessed.
        _isPossessed = true;
        _isPossessor = isMe;

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

    // When the player is removed from 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;
    }
}

Constructors

Methods

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

Fields

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

See Also