Skip to content

Latest commit

 

History

History
191 lines (133 loc) · 6.33 KB

GettingStarted-Multiplayer.md

File metadata and controls

191 lines (133 loc) · 6.33 KB

Getting Started for Multiplayer

To use the multiplayer function, you need to set the Extenject installer to the SceneContext object.

  • You are also required to set up ARUtility for the Multiplayer function.

Avatar System

namespace: Conekton.ARMultiplayer.Avatar.Domain

The Avatar System is used for visualizing the 3D-positions of person's head, hands, and controllers. This system helps you to visualize and recognize remote players' positions while using the multiplayer function.

Avatar Prefab

You can change objects under the Avatar System either by directly switching prefabs at Assets/Conekton/Multiplayer/Prefabs/Avatar or by switching the reference to prefabs at AvatarInstaller. See the following to check the interface of the Avatar System.

public interface IAvatarService
{
    IAvatar Create();
    void Remove(AvatarID id);
    IAvatar Find(AvatarID id);
    IAvatar GetMain();
}

Generation of an Avatar

An avatar is generated with the Avatar Prefab. When you execute Create, you can generate an avatar with the IAvatar interface. The main avatar is automatically generated, which means you don't need create it manually . If you want to get a reference to the main avatar, you can use the GetMain() function. If you want to get references to avatars you create, you can use the Find(AvatarID id) function with the references to avatar IDs.

IAvatar

A object generated by the Avatar System has the IAvatar interface, which is detailed below. The IAvatar interface is mainly used for getting the avatar status, such as Transform.

public interface IAvatar
{
    AvatarID AvatarID { get; }
    IAvatarController AvatarController { get; }
    Transform Root { get; }

    void SetAvatarController(IAvatarController controller);
    void SetWearablePack(IAvatarWearablePack pack);
    void SetWearable(IAvatarWearable wearable);

    Transform GetTransform(AvatarPoseType type);
    Pose GetPose(AvatarPoseType type);
    Pose GetLocalPose(AvatarPoseType type);
    void Destory();
}

IAvatarController

The IAvatarinterface is controlled by an object with the IAvatarController interface, which is also used for synchronizing the positions of remote players via the network.

public interface IAvatarController
{
    Pose GetHeadPose();
    Pose GetHandPose(AvatarPoseType type);
}

IAvatarWearable

The Avatar System provides the IAvatarWearable interface that allows you to place objects on the avatars' head and hands. By attaching an object with this interface to an avatar, you can place objects at target locations.

public interface IAvatarWearable
{
    AvatarWearType WearType { get; }
    void TargetTransform(Transform trans);
    void Unwear();
}

AvatarWearType is detailed below. You can attach objects to head, left hand, and right hand.

public enum AvatarWearType
{
    None,
    Head,
    Left,
    Right,
}

Setting up Multiple Avatar Objects with IAvatarWearablePack

IAvatarWearable is targeted to one object. If you want to use multiple objects collectively, you can use IAvatarWearablePack. You can set any number of wearable objects to target objects by implementing the IAvatarWearablePack interface.

public interface IAvatarWearablePack
{
    IAvatarWearable[] GetWearables();
}

Installer

You need to use AvatarInstaller to active the IAvatarSystem function.

Multiplayer Network System

namespace: Conekton.ARMultiplayer.NetworkMultiplayer.Domain

The Multiplayer Network System is offered for the multiplayer function. The system interface is detailed below.

public interface IMultiplayerNetworkSystem
{
    event ConnectedEvent OnConnected;
    event DisconnectedEvent OnDisconnected;
    event CreatedRemotePlayerEvent OnCreatedRemotePlayer;
    event CreatedLocalPlayerEvent OnCreatedLocalPlayer;
    event DestroyedRemotePlayerEvent OnDestroyedRemotePlayer;
    bool IsConnected { get; }
    void Connect();
    void Disconnect();
    PlayerID ResolvePlayerID(object args);
    PlayerID GetPlayerID(AvatarID avatarID);
    AvatarID GetAvatarID(PlayerID playerID);
    void CreateRemotePlayerLocalPlayer(IRemotePlayer remotePlayer, object args);
    void CreatedRemotePlayer(IRemotePlayer remotePlayer, object args);
    void RemoveRemotePlayer(IRemotePlayer remotePlayer);
}

You can install the network system instantly. *As default, you are required to use your App ID. If you already set your Photon ID properly, the system automatically starts to connect to your Photon server.

Handling Events

The IMultiplayerNetworkSystem interface is mainly used for handling events. The IMultiplayerNetworkSystem interface manages events for the following delegate methods.

  • public delegate void ConnectedEvent();
  • public delegate void DisconnectedEvent();
  • public delegate void CreatedRemotePlayerEvent(IAvatar avatar, IRemotePlayer remotePlayer);
  • public delegate void CreatedLocalPlayerEvent(IAvatar avatar, IRemotePlayer remotePlayer);
  • public delegate void DestroyedRemotePlayerEvent(IAvatar avatar, IRemotePlayer remotePlayer);

ConnectedEvent

The event called when the system is connected to the server.

DisconnectedEvent

The event called when the system is disconnected from the server.

CreatedRemotePlayerEvent

The event called when other players join and their play objects are generated. You get avatar information and remote player information as parameters.

CreatedLocalPlayerEvent

The event called when remote players are locally generated. These contain the same parameters as when CreatedRemotePlayerEvent is called except that it include the information of your avatar.

DestroyedRemotePlayerEvent

The event called when remote players have lost the connection and their player objects are destroyed.

Switching Avatar IDs

Remote players used in the network system is closely linked to the avatar system. Their position of head and hand is visualized with the reference to the avatar system. If you need a reference to a remote player of the targeted avatar, or vice versa, you can mutually switch avatar IDs via the following interface.

PlayerID GetPlayerID(AvatarID avatarID);
AvatarID GetAvatarID(PlayerID playerID);

Installer

You need to use NetworkMultiplayerInstallerto activate the IMultiplayerNetworkSystem function.