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.
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.
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();
}
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.
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();
}
The IAvatar
interface 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);
}
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,
}
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();
}
You need to use AvatarInstaller
to active the IAvatarSystem
function.
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.
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);
The event called when the system is connected to the server.
The event called when the system is disconnected from the server.
The event called when other players join and their play objects are generated. You get avatar information and remote player information as parameters.
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.
The event called when remote players have lost the connection and their player objects are destroyed.
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);
You need to use NetworkMultiplayerInstaller
to activate the IMultiplayerNetworkSystem
function.